jQuery UI Widgets Forums Grid Wrong datarow with updaterow

This topic contains 2 replies, has 2 voices, and was last updated by  Aikidotzu 10 years, 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Wrong datarow with updaterow #57381

    Aikidotzu
    Participant

    Hi,

    I was using the “addrow” feature with “first” so new data would appear on top of the grid— works great, but when I use updaterow, it is not updating the correct row— it’s updateing the row under it, so it appears to be off 1 after I call a addrow.

    I call the addrow like this:
    $(“#<mygrid>”).jqxGrid(‘addrow’, null, d, ‘first’); // where d = new data

    If I edit the second row which datarow says is 1, the 3rd row (2) is updated instead with..
    $(#<mygrid>”).jqxGrid(‘updaterow’, data_row, d) // data_row was collected from the event args when the line was clicked

    Please advise,
    Thanks.

    Wrong datarow with updaterow #57388

    Dimitar
    Participant

    Hello Aikidotzu,

    Here is an excerpt from the API Documentation about updaterow:

    // @param row id. Use the ‘getrowid’ method to get the id of a row.
    // @param row data. The expected value is a JSON object.
    var value = $(‘#jqxGrid’).jqxGrid(‘updaterow’, rowid, newdata);

    As you can see, the method takes the row’s id as a parameter, which is not always the same as its index. I guess the rows were with ids equal to their indexes but then you added the new row and specified its row id to be auto generated (the first parameter = null). Now the second row has an id of 0, the third – 1, etc. These are unchanged from before. You can get the new row’s id with the method getrowid.

    Best Regards,
    Dimitar

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

    Wrong datarow with updaterow #57413

    Aikidotzu
    Participant

    The problem is that by inserting the new data to the first row, it unsorts or dis-organizes the way the data is stored. The uid’s go 0,1,2,3… but the new row on the top becomes 4, or whatever the next would be, possibly normally on the bottom of the list; hence 4,0,1,3… By using the args.rowindex under non-use of the addrow function would work because there is a 1:1 ratio between rowindex and the uid. Once you start add rows to the top, this is no longer valid. I found an alternate solution however:

    data_row = e.args.rowindex; // gets the selected row index
    data = $(“<mygrid>”).jqxGrid(‘getrowdata’, data_row); // gets the data for the row

    *NEW*
    data_row = Number(data[“uid”]); // sets the proper row index

    When this is called, it updates the correct row now:
    $(“<mygrid>”).jqxGrid(‘updaterow’, data_row, d); // where d contains the object of the updated data

    Thanks for you input,
    Regards.

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

You must be logged in to reply to this topic.