I am enclosing a grid within a form. Normally, I would select records using checkboxes like this:
input name="itemid[]" value="12" type="checkbox"
That way I can easily process the array with php like
foreach $itemid as $value{
etc etc
So my question is: How can I name the checkboxes like that?
It is not doable now as it need major changes in how jqgrid javascript component is built.
What you can do is to get all selected checkboxes id using following js code and post them separately.
<script>
var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); // returns null if no row is selected (single row)
var selr = jQuery('#list1').jqGrid('getGridParam','selarrrow'); // array of id's of the selected rows when multiselect options is true. Empty array if not selection
</script>
I have done it before with this component. Like this:
colNames:['Description','Inclusions','Code','RRP'],
colModel :[
{formatter: cboxFormatter,name:'supplier_description', index:'supplier_description', width:335, align:'left'},
{name:'supplier_inclusions', index:'supplier_inclusions', width:610, align:'left'},
{name:'supplier_code', index:'supplier_code', width:230, align:'left'},
{name:'sale_price', index:'sale_price', width:90, align:'right', sortable:false}
],
and then
function cboxFormatter(cellvalue, options, rowObject)
{
return '<input type="checkbox" name="itemid[]" value="'+options.rowId+'" onclick="test('+options.rowId+',this.checked);"/> '+cellvalue;
}
I just have trouble "translating" this into my current setup with phpgrid.
You can use it in following manner …
$col = array();
$col["title"] = "Closed";
$col["name"] = "closed";
$col["width"] = "50";
$col["editable"] = true;
$col["edittype"] = "checkbox"; // render as checkbox
$col["editoptions"] = array("value"=>"1:0"); // with these values "checked_value:unchecked_value"
$col["formatter"] = "function(cellvalue, options, rowObject){ return cboxFormatter(cellvalue, options, rowObject);}";
<script>
function cboxFormatter(cellvalue, options, rowObject)
{
return '<input type="checkbox" name="itemid[]" value="'+options.rowId+'" onclick="test('+options.rowId+',this.checked);"/> '+cellvalue;
}
</script>
<div style="margin:10px">
<?php echo $out?>
</div>