Does JqGrid multiselect only give identifiers when the top checkbox is checked?

I have jqGrid with multiselect: true. In the button click event, I try to get identifiers like:

var ids = $('#myGrid').jqGrid('getGridParam', 'selarrrow');

However, I only get the ids to be populated with something if I select the top checkbox in the header. If I do not select this heading, but select several checkboxes in a column, identifiers do not have identifiers selected in it. How to overcome this?

sellarrover according to this example is spelled correctly: http://www.trirand.com/blog/jqgrid/jqgrid.html , select Advanced, Multiselect example.

+3
source share
5 answers

, :

beforeSelectRow: function(rowid, e) { return false; },

true, .

+2

HI add beforeSelectRow: cancelRowClickSelection,

jq grid. defenition . .

function cancelRowClickSelection(rowid, e) 
{
 var target=e.originalTarget;
 var str=target.innerHTML;
 if(target.classList!=null && target.classList!="undefined" && target.classList[0]!=null && target.classList[0]!="undefined")
 {
  if(target.classList[0]=="cbox")
  {
   return true;
  }
 }
 if(str.indexOf("input")!=-1 || str.indexOf("INPUT")!=-1)
 {
  return true;
 }
 return false; 
}
+2

I use the code below to retrieve randomly selected rows and its performance.

var selArr = $("#my_grid").getGridParam("selarrrow");
+1
source

if i put

$('#id ').getGridParam('selectarrow') 

instead

$('# ').JQgrid('getGridParam','selectarrow')

works

+1
source

I tried a few solutions presented with no luck. This is what I ended up with - just finding the data value ...

full standalone example.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <link type="text/css" rel="stylesheet" media="screen" href="jqGrid4/css/redmond/jquery-ui-1.8.13.custom.css" />
    <link type="text/css" rel="stylesheet" media="screen" href="jqGrid4/css/ui.jqgrid.css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <script type="text/javascript" src="jqGrid4/js/i18n/grid.locale-en.js"></script>
    <script type="text/javascript" src="jqGrid4/js/jquery.jqGrid.min.js"></script>
</head>
<body>

<form id="gridFIRST" action="A" method="post">
    <input id="gridFIRST_thinglist" name="gridFIRST[thinglist]" type="hidden" value="">
    <input id="gridFIRST_X"  name="gridFIRST[do_X]" type="submit" value="Let Out 0">
</form>
<form id="gridSECOND" action="B" method="post">
    <input id="gridSECOND_thinglist"  name="gridSECOND[thinglist]" type="hidden" value="">
    <input id="gridSECOND_Y" name="gridSECOND[do_Y]" type="submit" value="Bring In 0">
</form>
<table summary="grid" id="thisJqGrid"></table>
<div id="thisJqGridPager"></div>


<script>
function selectedThingsClass()
    {
    this.list = new Array();
    this.dpush = function(thing) { if(this.list.indexOf(thing) == -1) /* if unique */ this.list.push(thing); }
    this.dpop = function (thing) { var n = this.list.indexOf(thing); if(n >= 0) this.list.splice(n, 1); }
    this.getCount = function () { return 0+this.list.length; }
    this.thingSelected = function (isChecked,thing) { if(isChecked) this.dpush(thing); else this.dpop(thing); }
    }

function handleSelectedRow(thing) {
    var jqgcell     = jQuery('#thisJqGrid').getCell(thing, 0);
    var petName     = jQuery('#thisJqGrid').getCell(thing, 'COL2');
    var cbIsChecked = (jQuery(jqgcell).attr('checked') == 'checked') ? true : false;
    switch(petName)
        {
        case 'Dog':
            selectedThingsCat.thingSelected(cbIsChecked,thing);
            jQuery('#gridSECOND_thinglist').val(selectedThingsCat.list.toString());
            jQuery('#gridSECOND_Y').val("Bring In "+selectedThingsCat.getCount());
            break;
        case 'Cat':
            selectedThingsDog.thingSelected(cbIsChecked,thing);
            jQuery('#gridFIRST_thinglist').val(selectedThingsDog.list.toString());
            jQuery('#gridFIRST_X').val("Let Out "+selectedThingsDog.getCount());
            break;
        }
    }

var selectedThingsDog = new selectedThingsClass();
var selectedThingsCat = new selectedThingsClass();

function index_handleSelectedRow(rowIndex)
    {
    // convert row-index to JSON-Data ID
    var rowDataArr = jQuery("#thisJqGrid").getRowData();
    handleSelectedRow(rowDataArr[rowIndex].COL1);
    }

var mydata = [
    {id:"thing01",COL1:"thing01",COL2:"Dog"},
    {id:"thing02",COL1:"thing02",COL2:"Cat"},
    {id:"thing03",COL1:"thing03",COL2:"Cat"},
    {id:"thing04",COL1:"thing04",COL2:"Dog"},
    {id:"thing05",COL1:"thing05",COL2:"Cat"},
    {id:"thing06",COL1:"thing06",COL2:"Dog"},
    {id:"thing07",COL1:"thing07",COL2:"Cat"},
    {id:"thing08",COL1:"thing08",COL2:"Cat"},
    {id:"thing09",COL1:"thing09",COL2:"Dog"},
    {id:"thing10",COL1:"thing10",COL2:"Dog"}
    ];

jQuery(document).ready(function($){
    jQuery("#thisJqGrid").jqGrid({
            onSelectAll: function(rowIdxArray, sts)
                { jQuery(rowIdxArray).each(function(rowIndex){ index_handleSelectedRow(rowIndex); } ); },
            onSelectRow: function(rowJsonId)
                { handleSelectedRow(rowJsonId); },
            multiselect: true,
            colNames:[ 'Thing','Pet' ],
            colModel: [ { name:'COL1', width:10 }, { name:'COL2', width:10 }, ],
            datatype: "local", data: mydata,
            width: "200", height: "100%",
            postData: { "oper":"grid" },
            toolbar: [true,"top"],
            rowNum:10,
            sortname: "COL1",
            sortorder: "asc",
        });
    });

</script>
</body>
</html>
+1
source

Source: https://habr.com/ru/post/1726801/


All Articles