jQWidgets Forums

jQuery UI Widgets Forums Grid After updaterow saved clientside, I want to update the row client-side …

This topic contains 7 replies, has 2 voices, and was last updated by  Dimitar 9 years, 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author

  • markm123
    Participant

    After an update is made, I am having my script return the row values (after the update):
    “{“success”:true,”content”:{“id”:”96″,”name”:””,”annual_income”:”8787.00″,”job_title”:””,”stated_credit_score”:”9976″,”experian_credit_score”:null,”equifax_credit_score”:null,”transunion_credit_score”:null,”credit_report_source”:””,”is_cosigner”:”0″,”lastUpdated”:null}}”

    I am planning on adding a timestamp column so I need the row on the client-side to update with the new values from the DB:
    I tried: commit(true, rowid, data.content); and commit(true, data.content) but I can’t get the client-side row to update with fresh values from the DB after the update has finished (it does update the DB but I need to then update the client-side row with the actual values from the database)

    	    updaterow: function (rowid, rowdata, commit) {
    		
    		$.ajax({
    			dataType: 'json',
    			url: '/g/handler.php?h='+handlerName+'&masterId=' + masterID,
    			data: "update=true&id=" + rowid + '&' + $.param(rowdata),
    			success: function (data, status, xhr) {	
    			    if('success' in data) {
    				    if (data.success==true) {
    					    //alert(rowid);
    					    commit(true, rowid, data.content);
    				    }
    				    else {
    					    commit(false);
    					    alert('Error Updating Record');
    				    }
    			    }
    			    else {
    				    commit(false);
    				    alert('Unexpected Response From Server');
    			    }
    			    
    			},
    			error: function(jqXHR, textStatus, errorThrown) {
    			    commit(false);
    			    alert('Error Commmunicating With Server');
    			}		    
    		});		
    		
    	    }
    

    Please advise, thanks.


    Dimitar
    Participant

    Hello markm123,

    Are you sure commit(true, rowid, data.content); is actually called? If it is and the client-side row is still not updated, then please try calling only commit(true);. You can also try calling the method updatebounddata afterwards. If there are any errors thrown in your browser’s console while running your code, please share what they are.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/


    markm123
    Participant

    Yes because without the commit, nothing happends on the client-side… I tried:

    if (data.success==true) {
    commit(true);
    $(‘#’+ref).jqxGrid(‘updatebounddata’, data.content);
    }

    data JSON response below (contains all rows as required per updateboundata):
    {“success”:true,”content”:[{“id”:”96″,”name”:””,”annual_income”:”8787.00″,”job_title”:””,”stated_credit_score”:”9976″,”experian_credit_score”:null,”equifax_credit_score”:null,”transunion_credit_score”:null,”credit_report_source”:””,”is_cosigner”:”0″,”lastUpdated”:null},{“id”:”97″,”name”:””,”annual_income”:”88.00″,”job_title”:””,”stated_credit_score”:””,”experian_credit_score”:null,”equifax_credit_score”:null,”transunion_credit_score”:null,”credit_report_source”:””,”is_cosigner”:”1″,”lastUpdated”:null}]}

    However another call is being made to the server to get updated data …

    Is there anyway to update the local data from the JSON response given after an update?

    I should also note that the rowid is my databases unique ID (I have it specified in the data source id: ‘id’,).

    Perhaps commit needs some other type of rowid or does it know that the ID I am referring to is the one my server assigned it…


    markm123
    Participant

    Correction: I know commit(false) works because the client-side row is reverted back to previous changes upon updaterow when that statement is present. I don’t know that commit(true) is being called as nothing on the client-side indicates it (Given the fact that the local row is not updating from server-side data after updaterow)

    I am receiving no errors however…


    Dimitar
    Participant

    Hi markm123,

    In the updaterow callback, commit “knows” which row you have updated. The second parameter of commit is relevant only in the addrow callback.

    You can test if the commit(true); line is called with an alert or by placing a breakpoint (in Microsoft Visual Studio or Google Chrome’s Developer tools for example). If everything is correctly set up, commit(true) should update the client-side row without any additional code.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/


    markm123
    Participant

    Yes, commit(true) is being called but I still cannot get the local-row to update with fresh data from the server without it making a second call…

    The only solution I can possibly see is:

    
    					commit(true);
    					
    					$.each(data.content, function(k, v) {
    						if ($('#'+ref).jqxGrid('iscolumnvisible', k)) {
    							$('#'+ref).jqxGrid('setcellvalue', rowindex, k, v);
    						}
    					});
    

    Are you sure that the commit(..) function within the updaterow function supports updating the local row with JSON supplied in 2nd parameter if present?

    Example:
    updaterow: function (rowid, rowdata, commit) {
    var newdata = {full_name: “abc”};
    commit(true, newdata);
    }

    And as a result, the column in that local row would be updated with “abc” regardless with what rowdata contains..


    markm123
    Participant

    Actually, upon further testing … setcellvalue is re-invoking the updaterow function (a variable would have to passed/updated to tell it not to update)


    Dimitar
    Participant

    Hi markm123,

    In updaterow, commit should be passed only one boolean argument with a value of true or false. If the it is true, the client-side row will be updated. A second argument can be passed to commit only in the addrow callback. I think your code should simply be:

    success: function(data, status, xhr) {
        if ('success' in data) {
            if (data.success == true) {
                commit(true);
            } else {
                commit(false);
                alert('Error Updating Record');
            }
        } else {
            commit(false);
            alert('Unexpected Response From Server');
        }
    },

    Our tutorial Build CRUD Web App with jqxGrid using PHP and MySQL shows a working implementation of the three server synchronisation callback functions. Please check it out.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.