0

I am using jqGrid in my application and I have to select the currently selected row index. I am using this code.

var selectedrow = $('#s_1_l').jqGrid('getGridParam','selrow');

But I found out from this http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options site that if I use paging it will set to null. Is there any way I can get the selected row if I am using paging in jqGrid?

Thanks.

Chiranjit
  • 53
  • 1
  • 8

1 Answers1

1

jqGrid support selrow only for the current page. There are no support of any kind of persistence of selected row.

There are many ways (which are not always simple) to implement different scenarios of persistent selection.

For example the answer and this one one demonstrate how one can implement saving selected rows independent from the paging.

The demo which I created for the answer shows how to persist the current page and the selected row. Just try to select a row then change the page and go to the original page back. You will see that the selected row stay selected. The demo saves selected row, the current page number and some other states in the localStorage of the web browser. So if you even reload the page (with F5) or close the web browser and open it one more time on the same page you will see the same row selected and the same page chosen.

I hope that above demos and the corresponding answers with descriptions will help you to solve your problem.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg Thanks so much for this elaborate reponse.Just to update that if I need to get the selected row in the current page how can I do that?Lets say I am in page 8 and in each page has 10 records.so if I select the 3rd record of page 8, I need to have the selrow index as 3, but because of paging its returning null.Can you please advise in this regard. – Chiranjit Mar 13 '14 at 10:14
  • @Chiranjit: You are welcome! It's very difficult to understand what you mean because you still don't included JavaScript code which you use and don't posed any test data. The `selrow` hold the **rowid** and not the **index**. Only if you have filled the grid in the wrong way (without specifying `id` of every item of data) then rowids will be 1,2,3... on every page. In the case you will be unable to distinguish between rowid=`3` on different pages. Moreover you wrotr about `null` value, but you don't posted **when** (inside of which callback or on which place of your code) you get `selrow`. – Oleg Mar 13 '14 at 10:23
  • yeah,Thnks once again.You are a lifesaver.You pionted out correctly, it was returning null because it was executing prior document load.That issue is fixed. The above code that I posted regarding selrow in my question is working fine.Can you please tell me how can I find a particular column value of that selected row in jqGrid? – Chiranjit Mar 13 '14 at 11:03
  • @Chiranjit: You are welcome! You can use `var cellValue = $("#s_1_l").jqGrid("getCell", selectedrow, "columnName");` for example to get the value from the cell which is in the row with the rowid `selectedrow` and the column with the name `"columnName"`. If you need to get all (or many) values you can use [getRowData](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods) instead of `getCell`. If you save data locally (`datatype: "local"` for example) then the best will be to use `getLocalRow`. – Oleg Mar 13 '14 at 11:58