0

jqGrid Code:

<script>
jQuery("#task-grid").jqGrid({
    url:call_url,
        datatype: "json",
    height: 'auto',
    rowNum: 20,
    rowList: [20,30],
    colNames:['ID','RESOURCE','ROLE','SITE', 'ALLOC. TYPE', 'UNIT (%)'],
    colModel:[
                {name:'ID',key:true,index:'ID', width:50, align:'center',search:false,hidden: true},
        {name:'RESOURCE',index:'RESOURCE', width:150, sorttype:"text",align:'center',search:true},
        {name:'ROLE',index:'ROLE',width:120 ,align:'center',search:false},
        {name:'SITE',index:'SITE', width:120, align:'center',search:false},
        {name:'ALLOC. TYPE',index:'ALLOCATION_TYPE', align:'center',width:120,search:false },
        {name:'UNIT',index:'UNIT',align:'center',search:false},     
        //{name:'HOURS',index:'HOURS', search:false, align:'center',sortable:false,editable:true}
    ],
    pager: "#page",
    shrinkToFit :true,
    autowidth: true,
    viewrecords: true,
    sortname: 'RESOURCE',
        sortorder: "asc",
        multiselect: true,
        cellEdit: true,
        cellsubmit : 'clientArray',
    caption: "Resource List"
}).navGrid('#page',{ edit:false,add:false,del:false,search:false,cloneToTop:true,refresh:false},
            {

             },{
             //add options

             },{

                        //msg: "do you really want delete this keyword? This delete affect on Eqms filter"

                });


                jQuery("#task-grid").jqGrid('filterToolbar', { autosearch: true  });
        var topPagerDiv = $('#grid_toppager')[0]; 
        jQuery("#grid_toppager_center", topPagerDiv).remove(); 
</script>

jqGrid structure:

<table id="task-grid" class="ui-jqgrid-btable" cellspacing="0" cellpadding="0" border="0" tabindex="0" role="grid" aria-multiselectable="true">
<tr style="height:auto" role="row" class="jqgfirstrow"></tr>
<tr class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" id="13551" role="row">
<td aria-describedby="task-grid_cb" style="text-align:center;width: 25px;" role="gridcell"><input type="checkbox" name="jqg_task-grid_13551" class="cbox" id="jqg_task-grid_13551" role="checkbox"></td>
</tr>
<tr class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" id="12860" role="row">
<td aria-describedby="task-grid_cb" style="text-align:center;width: 25px;" role="gridcell"><input type="checkbox" name="jqg_task-grid_13551" class="cbox" id="jqg_task-grid_13551" role="checkbox"></td>
</tr>
<tr class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" id="12855" role="row">
<td aria-describedby="task-grid_cb" style="text-align:center;width: 25px;" role="gridcell"><input type="checkbox" name="jqg_task-grid_13551" class="cbox" id="jqg_task-grid_13551" role="checkbox"></td>
</tr>
</table>

Keep this checkbox selected

Code to fetch ID's

var ids = jQuery("#task-grid").jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) 
                {
                    var rowId = ids[i];
                    console.log(rowId);
                }

Console log gives me ID's 13551, 12860 and 12855 which are <tr> ID's.

How can I match the rowId's with <tr> id's and keep the checkbox selected?

Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121
  • Sorry, but your question is absolutely unclear. If you want to "match DataID's with row ID's" then you should provide an example of your data (with the DataID's) and include jqGrid code which you use. It seems that you use `multiselect: true` option. What you mean under "keep the checkbox selected"? Do you want that some rows will be selected after loading of the grid? Or you want that changing the page to next and then back to the previous keep the selection? Or you want to keep the rows selected between different visits of the same page? I can continue... You need just explain what you need. – Oleg Nov 13 '14 at 19:58

1 Answers1

0

I looped through the rowArray array and call setSelection method for every rowid from the rowArray:

var i, count, $grid = $("#myTable");
for (i = 0, count = rowArray.length; i < count; i += 1) {
    $grid.jqGrid('setSelection', rowArray[i], false);
}

This code works.

Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121