2

My grid uses an XML ajax call to retrieve data. I would like to preselect a record when it loads initially. I have managed to accomplish this by setting a global javascript array, referencing it in loadComplete and calling setSelection, then clearing the array so it will not preselect again when paging, sorting, etc. Is there a more efficient way to do this that does not involve a global variable?

2Yootz
  • 3,971
  • 1
  • 36
  • 31
  • 1
    I do not know if it is more efficient or not but I do something similar except that I use the Jquery .data() property instead. That way if I have more than one grid they could each have their own property. – DisplayName Mar 20 '12 at 17:04
  • When I said efficient I was just wandering if there was something built-in to jgrid to handle pre-selection. I appreciate the feedback. – 2Yootz Mar 20 '12 at 18:17
  • Where you get the information about the rows which should be preselected? Is it information from the database and you sent it together with the response from the server? Is it the last rows which the user selected before? Do you use `loadonce: true` or use pure server based data? How many rows has the grid? I mean that in case of a few rows only the question about the performance is not really important. – Oleg Mar 20 '12 at 20:23
  • I would be repainting a previous selection by the user from the last time they visited the grid. The key(s) they selected would be stored in a separate database and would not be fetched in the ajax call. That data would actually be read prior to the grid being formed. I have not used `loadonce`. From what I'm reading it seems that my approach is not necessarily a bad one. That's what I was mainly trying to figure out. – 2Yootz Mar 20 '12 at 20:42
  • 2
    I personally think that it's good approach and not better question (I voted it up immediately). I wrote that performance of row selection is not so important in your case so you can do this in the way which corresponds the requirements. I would recommend you to try [the demo](http://www.ok-soft-gmbh.com/jqGrid/ColumnChooserAndLocalStorage2_.htm) wich save selection state *over* pages ([the answer](http://stackoverflow.com/a/8547852/315935)) and to read my [feature request](http://www.trirand.com/blog/?page_id=393/feature-request/save-selected-state-of-multiselect-rows-over-the-paging/#p25181). – Oleg Mar 20 '12 at 21:31

0 Answers0