jQWidgets Forums

jQuery UI Widgets Forums Grid What is "commit" doing ?

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • What is "commit" doing ? #24879

    tuthmosis
    Member

    That may be a stupid question but i cannot find that function the API doc…

    addrow: function (rowid, rowdata, position, commit) {
    // synchronize with the server - send insert command
    rowdata.id = "";
    var data = "insert=true&" + $.param(rowdata);
    $.ajax({
    dataType: "json",
    url: "data.php",
    data: data,
    success: function (data, status, xhr) {
    commit(true, data.id);
    },
    error: function (jqXHR, textStatus, errorThrown) {
    commit(false);
    }
    });
    },
    What is "commit" doing ? #24895

    Peter Stoev
    Keymaster

    Hi,

    “commit” with parameter true commits the changes and updates the UI. “commit” with parameter false, cancels the changes in the UI.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    What is "commit" doing ? #73891

    iceboxx89
    Participant

    since commit takes commit(true, data.new_id_from_db) is the below possible ?

    
    updateRow: (rowid, newdata, commit) ->
        $.ajax(
         ..
        ).done(
         (updated_data) ->
             commit(true, updated_data)
        )
    

    updated_data is the JSON Object from the database in which fields like lastupdated_on, etc.. might have changed. updatebounddata essentially does a GET again for the entire set, can that be prevented ?

    Regards,

    What is "commit" doing ? #75703

    BenR
    Participant

    Hello JQ widgets Team.

    I am having a similar issue…

    Doing a test with MVC5 and editing a datagrid …

    I am able to display records, when I edit them, the table cell displays the previous value, but if I refresh the screen, it will disply the new value. So I know the value is being written to the database.

    It seems my code related to “updaterow” is having an issue with the AJAX call and ses teh AJAX call as an “error:” rather than a “success”. This is confirmed by “Alert()” code I have injected for debuggin purposes.

    Here is an excerpt of my code …

    
       <script type="text/javascript">
            $(document).ready(function () {
                // prepare the data
                //var data = {};
                var source =
                {
                    dataType: "json",
                    dataFields: [
    
                        { name: 'id', type: 'number' },
                        { name: 'car', type: 'string' },
                        { name: 'title', type: 'string' },
                        { name: 'proj_mgr_id', type: 'string' }
    
                    ],
                    id: 'id',
                    url: '/Project/GetProjects'
                    ,
                    updaterow: function (rowid, rowdata, commit) {
                        // synchronize with the server - send update command
                        data = "update=true" +
                                    "&car="             + rowdata.car +
                                    "&title="           + rowdata.title +
                                    "&proj_mgr_id="     + rowdata.proj_mgr_id +
                                    "&id="              + rowdata.id;
                        //rowdata.id = rowid;
                        $.ajax({
                            dataType: 'json',
                            //cache: false,
                            url: '/Project/UpdateProject',
                            data: rowdata,
                            type: "POST",
                            success: function (data, status, xhr) {
                                // update command is executed.
                                commit(true);
                                //commit(true, data.id);
                                alert('Worked!');
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                // update failed.
                                commit(false);
                                alert('Did not work');
                                commit(true);
                            }
                        });
                    }
                }
                var dataAdapter = new $.jqx.dataAdapter(source);
                // create Tree Grid
                $("#dataTable").jqxDataTable(
                {
                    width: 850,
                    source: dataAdapter,
                    theme: 'arctic',
                    editable: true,
                    //editmode: 'selectedcell',
                    pageSize: 5,
                    sortable: true,
                    filterable: true,
                    pageable: true,
                    columns: [
    
                        { text: 'id', dataField: 'id', width: 10 },
                        { text: 'car', dataField: 'car', width: 20 },
                        { text: 'title', dataField: 'title', width: 160 },
                        { text: 'proj_mgr_id', dataField: 'proj_mgr_id', width: 500 } 
                    ]
                });
    
            });
        </script>
    }
    <div id="dataTable">
    </div>
    
    What is "commit" doing ? #75705

    BenR
    Participant

    In response to my own question … Solution found! (see prior post, above)

    The line of code $("#dataTable").jqxDataTable(

    which should have been $("#dataTable").jqxGrid(

    I was really wanting to work with grid control and not the datable. I think the datatable was copied in from another sample/location, but I did not catch it for some time. The error/success response in the AJAX call was not properly handled in the datatable control, but started working after I changed controls. I also adjusted my MVC controller (and the code above to use a post directive) in order properly utlize the AJAX request in my MVC code. I used the example “CRUD with jqxGrid, ASP.NET MVC3 and SQL“.

    I hope this helps some one else in this obscure issue.

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

You must be logged in to reply to this topic.