Author Topic: SetSelection does not work  (Read 5152 times)

jax

  • Newbie
  • *
  • Posts: 16
    • View Profile
SetSelection does not work
« on: July 08, 2014, 08:21:29 am »
When I try to set the selection nothing happens. The same line works in the console after the grid has already loaded, but whether I put the setSelection call after or before the grid initializing it still does not work. The grid is being loaded via an ajax call so i tried to bind to the load event but it still does not work.

Code: [Select]
obj.create = function (evt, ui) {
            $("#grid_editing").pqGrid("setSelection", { rowIndx: 1 });
        }

var $grid = $('#grid_editing').pqGrid(obj);

Does the grid not allow you to set the selection if you are loading via ajax? I have tried in the load event

Code: [Select]
load: function(event, ui) {
                 $('#grid_editing').pqGrid('setSelection', { rowIndx: 1 });
            },

And also binding to the load event like this. No matter what I try it doesn't set the selected row but again if I run the same code through the console it will select the row so I know the syntax and data is correct it just appears to be an issue with grid itself unless I am missing something but I have tried almost everything I can think of at this point.

Code: [Select]
$( "#grid_editing" ).on( "pqgridload", function( event, ui ) {$('#grid_editing').pqGrid('setSelection', { rowIndx: 1 });} );
« Last Edit: July 08, 2014, 09:20:50 am by jax »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: SetSelection does not work
« Reply #1 on: July 08, 2014, 10:22:42 am »
jax

You are right, it's an issue with grid load event in relation to setSelection.

As a workaround you could use window.setTimeout

Code: [Select]
$( "#grid_editing" ).on( "pqgridload", function( event, ui ) {
  window.setTimeout( function(){
    $('#grid_editing').pqGrid('setSelection', { rowIndx: 1 });
  }, 0);
});