Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
No New ID : add method afterSubmit new_id with json datatype
14/12/2010
18:13
Avatar
immobilia
France
Member
Members
Forum Posts: 10
Member Since:
26/10/2010
sp_UserOfflineSmall Offline

Hi, i have read http://www.trirand.com/jqgridw.....rm_editing explain :

but, it doesnt work for me with last version (3.8.2 full options).

Server return new_id, correctly read on client side, but not updated by jqGrid.

fires after response has been received from server. Typically used to display status from server (e.g., the data is successfully saved or the save cancelled for server-side editing reasons). Receives as parameters the data returned from the request and an array of the posted values of type id=value1,value2.
When used this event should return array with the following items [success, message, new_id]
where
success is a boolean value if true the process continues, if false a error message appear and all other processing is stopped. (message is ignored if success is true).
new_id can be used to set the new row id in the grid when we are in add mode.
afterSubmit : function(response, postdata)
{

return [success,message,new_id]
}

Sample : jqGridAddNewId.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jqGrid</title>

<script type="text/javascript" src="jquery/js/jquery-1.4.4.min.js"></script>
<link type="text/css" href="jquery/css/ui-lightness/jquery-ui-1.8.6.custom.css" rel="stylesheet" />
<script    type="text/javascript" src="jquery/js/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript" src="jquery/development-bundle/ui/i18n/jquery.ui.datepicker-fr.js"></script>

<link rel="stylesheet" type="text/css" media="screen" href="jquery/plugins/jqGrid/src/css/ui.jqgrid.css" />
<script src="jquery/plugins/jqGrid/js/i18n/grid.locale-fr.js" type="text/javascript"></script>
<script src="jquery/plugins/jqGrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>

</head>
<body>

<script type="text/javascript">
$(function() {
    
    var mygrid = jQuery("#liste").jqGrid({

        altRows: true,
        autowidth: true,
        height: "100%",

        multiselect: true,
        
        url:"jqGridAddNewId_fetch.php",    // server.php?q=2
        editurl:"jqGridAddNewId_add.php",
        datatype: "json",
        colNames:['Id','Name'],
        colModel:[            
                    {name:'pack_id', index:'pack_id', width:15, align:"center",
                        hidden:false,
                        key: true
                    },
                    {name:'name', index:'name', width:200,
                        editable:true,
                        editrules:{required:true},
                        formoptions:{ elmprefix:"(*)"}    // rowpos:1, elmprefix:"(*), elmsuffix:" yyyy-mm-dd"
                    }
                ],
        rowNum:10,    // default : 20
        rowList: [10,20,30,50,100],
        pager: '#pagerList',

        sortname: 'pack_id',
        sortorder: 'desc',
        viewrecords: true,
        caption: "List",
        jsonReader: {
            repeatitems : false
        }                

    });

    jQuery("#liste").jqGrid('navGrid','#pagerList',
            {
                edit:true,add:true,del:true,search:true,view:true,refresh:true
            },
            {closeOnEscape:true,jqModal:true,bottominfo:"Fields marked with (*) are required",
                reloadAfterSubmit:false,
                closeAfterEdit:true,
                afterSubmit:function(response,postdata){
                    var message = "";
                    var json = eval('(' + response.responseText + ')');
                    var success = json.success;
                    if(json.errors) {
                        for(i=0; i < json.errors.length; i++) {
                            message += json.errors[i]['error'] + '<br/>';
                        }
                    }
//                    var new_id = "1";
//                    return [success,message,new_id];
                    return [success,message];
                }
                    // response.responseText
            }, // edit options
            {closeOnEscape:true,jqModal:true,bottominfo:"Fields marked with (*) are required",
                reloadAfterSubmit:false,
                closeAfterAdd:true,

                afterSubmit:function(response,postdata){
                    var success = false;
                    var message = "";
                    var new_id = 0;
                    try{
                        var json = eval('(' + response.responseText + ')');
                        success = json.success;
                        new_id = json.sql_id;

                        if(json.errors) {

                            for(i=0; i < json.errors.length; i++) {
                                message += json.errors[i]['error'] + '<br/>';
                            }
                        }
                    }catch (e) {
                        message = e.name + " : " + e.message;
                    }

//                    var new_id = "1";
//                    alert("[" + success + "," + message + "," + new_id + "]");
                    return [success,message,new_id];
                }
            }, // add options
            {closeOnEscape:true,jqModal:true}, // del options
            {closeOnEscape:true,jqModal:true,multipleSearch:true}, // search options
            {closeOnEscape:true, multipleSearch:true, closeAfterSearch: true, closeAfterReset: true, modal:true}, // search options
            {closeOnEscape:true} // view options
        );    
    
});
</script>

<table id="liste"></table> <div id="pagerList"></div>

</body>
</html>

jqGridAddNewId_add.php

{"success":true,"sql_id":"16"}

jqGridAddNewId_fetch.php

{"page":"1","total":2,"records":"2","rows":[{"pack_id":"10","name":"name_10"},{"pack_id":"11","name":"name_11"}]}

15/12/2010
11:57
Avatar
immobilia
France
Member
Members
Forum Posts: 10
Member Since:
26/10/2010
sp_UserOfflineSmall Offline

in grid, default parameter id is "id",

to change and add link with primary key you must redefine like

prmNames: {id: "pack_id"},

but, why i doesn't use the primary key of colModel instead ?...

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
71 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information