Match DataID's with row ID's

691 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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.