开发者

jqgrid edit button accessing a set of checkboxes that are selected

开发者 https://www.devze.com 2023-03-07 16:02 出处:网络
I have the below code in my jqgrid <script type=\"text/javascript\"> jQuery(document).ready(function() {

I have the below code in my jqgrid

<script type="text/javascript">
    jQuery(document).ready(function() {

        var grid = jQuery("#list");
        $("#editBtn").click(function() {
           alert("hi");                            });


        jQuery("#list").jqGrid({
            url: '<%= Url.Action("DynamicGridData") %>',
            datatype: 'json',
            mtype: 'POST',

            colNames: ['checkbox',  'Id','col1','col2' ],
            colModel: [
      { name: 'checkbox', index: 'checkbox', sortable: false, formatter: "checkbox", formatoptions: { disabled: false }, editable: true, edittype: "checkbox" },
               { name: 'Id', index: 'Id', search: false, stype: 'text', sortable: true, sorttype: 'int', hidden: true },
      { name: 'col1', index: 'col1', search: false, stype: 'text', sortable: true, sorttype: 'int', search: false, hidden: true },
      { name: 'col2', index: 'col2', sortable: true, search: false, width: 30, stype: 'int' } ],
            pager: jQuery('#pager'),
            rowNum: 40,
            rowList: [20, 40, 60, 100],
            sortname: 'Id',
            sortorder: 'asc',
            gridview: true,
            autowidth: true,
            rownumbers: true,
        开发者_JS百科    viewrecords: true,
            toppager: true,
            height: "100%",
            width: "100%",
           caption: 'Grid Data'
        });



    });

I can fire the test alert in the editBtn function, how can a user access the id column of the records that have their checkboxes selected by the user?


use the following code to get the Id column data of which checkboxes are ticked...

var grid = jQuery("#list");
$("#editBtn").click(function() {
   var str = '';
   var data = grid.getRowData();
   for(i=0;i<data.length;i++){
        if(data[i].checkbox==='Yes')
            str += data[i].Id+',';
   }
   alert(str);
});

str variable consists of the values of Id column for which checkbox is selected by user.

0

精彩评论

暂无评论...
验证码 换一张
取 消