remember after refresh selected row in extjs grid

后端 未结 5 1565
借酒劲吻你
借酒劲吻你 2020-12-17 14:56

I have a problem. I use extjs grid. This grid will be refreshed every seconds.

I refresh with this function:

ND.refresh =          


        
5条回答
  •  天涯浪人
    2020-12-17 15:32

    Here is another way to select the previously selected record:

    var selectionModel = grid.getSelectionModel()
    
    // get the selected record
    var selectedRecord = selectionModel.getSelection()[0]
    
    // get the index of the selected record
    var selectedIdx = grid.store.indexOfId(selectedRecord.data.id);
    
    // select by index
    grid.getSelectionModel().select(selectedIdx);
    

    For some reason the grid.getSelectionModel().select(record) method wasn't working for me, but selecting by index seems to work.

    Edit: found out why grid.getSelectionModel().select(record) method wasn't working. Apparently the store is reloaded, the record instances aren't the same (they have different automatically generated Ext IDs). You have to use selectAt() in this case.

提交回复
热议问题