如何在显示时选择整个jqgrid

时间:2016-01-22 09:10:50

标签: jquery asp.net-mvc jqgrid

如何在显示时选择整个jqgrid(我的意思是jqgrid的所有复选框)。请参阅附带的代码。我在jqgrid中成功显示数据,但我需要默认选中所有复选框。

代码: -

 $grid.jqGrid({
            datatype: "local",
            data:mydata,
            colModel: [
              { name: "accntname", align: "center", title: false, width: 400, resizable: false, sortable: false },
              { name: "BU", width: 125 },
              { name: "salesop", align: "center", width: 125, sorttype: "date" },
              { name: "isdormant", align: "center", width: 125, sorttype: "date" }
            ],
            caption: "Viz Test",
            pager: '#pager',
            search: true,            
            multiselect: true,
            editoptions: { value: "Yes:No", defaultValue: "Yes" },
            onSelectRow: function (id, status)
            {
                var rows = $("#oversight-sample").jqGrid('getGridParam', 'selarrrow');
                var totalRow = rows.length;
                var totalAmount = 0;
                $.each(rows, function () {
                    var rowData = $("#oversight-sample").getRowData(this);
                    totalAmount += rowData["salesop"] * 1;
                });
                dataTable.row($('#ex').find('tbody tr')).remove().draw();
                dataTable.row.add([totalRow, totalRow,totalAmount,totalRow]).draw();
                var rowData = jQuery(this).getRowData(id);
                Accntname = rowData["accntname"];
                BU = rowData["BU"];
                SalesOp = rowData["salesop"];
                Isdormant = rowData["isdormant"];
                var ch = jQuery(this).find('#' + id + ' input[type=checkbox]').prop('checked');
                if (ch)
                {

                    $.ajax({
                        url: '/TodoList/I_am_temporary',
                        data: { 'Accntname': Accntname, 'BU': BU, 'SalesOp': SalesOp, 'Isdormant': Isdormant },
                        type: "post",
                        success: function (response)
                        {
                            var rows = response.rows;
                            $.each(rows, function () {
                                //alert(JSON.stringify(rows));
                                fncount.push(this.accntname);                                
                                lncount.push(this.BU);
                                sale.push(this.salesop);
                                m = m + this.salesop;

                                gndr.push(this.isdormant);                                

                            });

                        }
                    });
                    //alert(fncount.length+""+lncount.length+""+sale.length+""+gndr.length);
                }

            },
            onSelectAll: function (id, status) {
                var rows = $("#oversight-sample").jqGrid('getGridParam', 'selarrrow');
                var totalRow = rows.length;
                var totalAmount = 0;
                $.each(rows, function () {
                    var rowData = $("#oversight-sample").getRowData(this);
                    totalAmount += rowData["salesop"] * 1;
                });
                dataTable.row($('#ex').find('tbody tr')).remove().draw();
                dataTable.row.add([totalRow, totalRow, totalAmount, totalRow]).draw();

                var allRowsInGrid = $grid.jqGrid('getRowData');
                $.each(allRowsInGrid, function (i, item) {

                            fncount.push(this.accntname);
                            lncount.push(this.BU);
                            sale.push(this.salesop);
                            gndr.push(this.isdormant);
                        })

            }

        });

Image

0 个答案:

没有答案