jqGrid local data manipulation; problem with row ids when deleting and adding new rows

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-04-27T09:37:23Z Indexed on 2010/04/28 8:13 UTC
Read the original article Hit count: 857

Filed under:
|
|

I'm using jqGrid as a client side grid input, allowing the user to input multiple records before POSTing all the data back at once.

I'm having a problem where if the user has added a few records (say 3 ) the id's for the records will be 1,2,3. if the user deletes record 2, you're left with 1 and 3 for the id of the records.

When the user now adds a new records, jqGrid assigns that records the id 3 again since it just seems to count the total records and increments it by one for the new record. This causes problems when selecting rows as now the row id's are 1, 3 and 3.

Does anyone know how to access the row ids of records as I could probably use the afterSubmit event and reassign the row id's increasing from 1. ( so after i delete row id 2, this will set the other row id's to 1 and 2)

Any other suggestions to solve this problem?

Thanks

edit I've solved this with the following code for the delete navGrid button

  }).navGrid('#pager', {add:true, del:true, refresh:false, search:false},
    {
    ...
    }, ##edit parameters
    {
    ...
    }, ##add parameters
    {reloadAfterSubmit:false,
    clearAfterAdd:false,
    afterComplete:
        function () {
            ## clear and readd the row data so the row ids are sequential
            var savedData= $("#inputgrid").jqGrid('getRowData');
            $("#inputgrid").jqGrid('clearGridData');
            $("#inputgrid").jqGrid('addRowData', 'rn', savedData);

        }
    }  ##delete parameters
);

Basically just saving the grid data and then re-adding it so that the rowids are sequential again.

For some reason it causes the row numbers down the left side to go start from 2 instead of one. Edit this was solved by using the latest jqGrid code in GitHub (27th April 2010)

© Stack Overflow or respective owner

Related posts about jqgrid

Related posts about JavaScript