jQWidgets Forums

jQuery UI Widgets Forums Grid Add Row with returned db id

This topic contains 2 replies, has 2 voices, and was last updated by  Peter Stoev 11 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Add Row with returned db id #53907

    EricK
    Participant

    Hopefully this is simple. I am tring to add a row using ajax json php.
    Here is the sample code:

    var source =
                {
                    datatype: "json",
                    datafields: [
                    	{ name: 'clientsid' },
    			{ name: 'companyname' },
    			{ name: 'address' }, 
    			{ name: 'city' },
    			{ name: 'region' },
    			{ name: 'phone' },
    			{ name: 'description' }
    
                    ],
                    cache: false,
                    id: 'clientsid',
                    url: 'clientdata.php',
                    filter: function()
    				{
    				// update the grid and send a request to the server.
    				$("#jqxgrid").jqxGrid('updatebounddata', 'filter');
    				},
    				sort: function()
    				{
    					// update the grid and send a request to the server.
    					$("#jqxgrid").jqxGrid('updatebounddata', 'sort');
    				},
    				addrow: function (rowID, rowData, position, commit) {
    					var data = 'insert=true';
    					$.ajax({
                            dataType: 'json',
                            url: 'clientdata.php',
                            data: data,
                            success: function (data) {
                                alert ('k:'+data[0].clientsid);
                                commit(true);
                            },
                            error: function () {
                                // cancel changes.
                                commit(false);
                            }
                        });
    }
    

    Everything works correctly. The grid shows a new row, and the code fires the insert process.
    My php file returns the encoded data:
    [{“clientsid”:”7880″}]
    The success function returns the clientsid.
    My grid does not have a column with the clientsid field. This is only part of the array of datafields.

    Two questions:
    1)How do I update the grid (array) with the new (key) clientsid?
    So when i select the new row it shows me the clientsid field now has a number.
    2) Do I have to return all of the datafields from my php process? (As I do when the grid is originally filled.)

    Thanks
    Eric

    Add Row with returned db id #53909

    EricK
    Participant

    One other question?
    If the grid is filtered. Does that have an effect on the add row process?

    Add Row with returned db id #53912

    Peter Stoev
    Keymaster

    Hi Erick,

    You may call use this:commit(true, data[0].clientsid);

    When you add new row, it will be displayed only if it meets the filtering criteria.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.