开发者

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

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 开发者_Python百科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). But I found out that that version of jquery.fmatter.js caused empty cells to show " " when you tried to edit the row so I had to revert that file back to the one in jqGrid 3.6.4.


Solved as indicated in the edit section of the question

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜