如何从jqgrid的所有页面中选择所有行

时间:2015-07-28 07:14:06

标签: javascript jquery jqgrid mvcjqgrid

如何在用户使用过滤器工具栏后获取未删除的所有rowsIDs

我的jqgrid:

enter image description here

我用:

var selRow = jQuery("#list").jqGrid('getGridParam', 'selarrrow'); 

但是这段代码得到了3行,我想要选择所有其他页面的行!!!

javascript代码:

   <script type="text/javascript">
    var searchOptions = ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'in', 'ni', 'ew', 'en', 'cn', 'nc'];


    $(document).ready(function () {

        $('#list').jqGrid({
            caption: "",
            //url from wich data should be requested
            url: '@Url.Action("GetAllMet", "MetGrid")',

            //type of data
            datatype: 'json',
            jsonReader: {
                root: "Rows",
                page: "Page",
                total: "Total",
                records: "Records",
                repeatitems: true,
                id: "MetID",
                cell: "RowCells"
            },
            //url access method type
            mtype: 'POST',
            //columns names
            colNames: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ' ', '', '', '', '', '', '', '', '', ''],
            //columns model
            colModel: [

                    {
                        name: 'MetID', index: 'MetID',
                        editable: false, hidden: true, key: true
                    },
                 {
                     name: 'WaterSharingNo', index: 'WaterSharingNo', align: 'center', width: 70,

                     search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                     editable: true, edittype: 'text'

                 },
                     {
                         name: 'PowerSharingNo', index: 'PowerSharingNo', align: 'center', width: 70,
                         //formatter: formatNumber,
                         search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                         editable: true, edittype: 'text'

                     }
            ,
                {
                    name: 'Serial', index: 'Serial', align: 'center', width: 70,
                    search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                    editable: true, edittype: 'text'

                },
                  {
                      name: 'TypeID_FK', index: 'TypeID_FK', align: 'center', width: 90,

                      search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                      editable: true, edittype: 'select',
                      editoptions: {

                          dataUrl: '@Url.Action("TypeMeterSelect", "MeterGrid")'

                      }
                  },
                {
                    name: 'UseID_FK', index: 'UseID_FK', align: 'center', width: 80,
                    search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                    editable: true, edittype: 'select',
                    editoptions: {
                        dataUrl: '@Url.Action("UseMetSelect", "MetGrid")'
                    }
                },



                 {
                     name: 'TypeModID_FK', index: 'TypeModID_FK', align: 'center', width: 90,

                     search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                     editable: true, editoptions: { readonly: 'readonly' }
                 },
                {
                    name: 'ModID_FK', index: 'ModID_FK', align: 'center', width: 80,
                    //formatter: formatNumber,
                    search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                    editable: true, edittype: 'text',
                    editoptions: {
                        dataInit: function (elem) {
                            // http://jqueryui.com/autocomplete/
                            $(elem).autocomplete({
                                source: '@Url.Action("GetModSerial","MetGrid")',
                                minLength: 2,
                                select: function (event, ui) {
                                    $(elem).val(ui.item.value);
                                    $(elem).trigger('change');
                                }
                            });
                        }
                    }

                },
             {
                 //shomare sim kart
                 name: 'ModCelNo', index: 'ModCelNo', align: 'center', width: 70,
                 search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                 editable: true, edittype: 'text'

             },

            {
                name: 'GroupID_FK', index: 'GroupID_FK', align: 'center', width: 70,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, edittype: 'select',
                editoptions: {
                    dataUrl: '@Url.Action("GroupSelect", "MetGrid")'

                }
            },
            {
                name: 'AffairID_FK', index: 'AffairID_FK', align: 'center', width: 90,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, edittype: 'select',
                editoptions: {
                    dataUrl: '@Url.Action("AffairSelect", "MetGrid")'
                }

            },
            {
                name: 'DesertID_FK', index: 'DesertID_FK', align: 'center', width: 90,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: true, edittype: 'select',
                editoptions: {
                    dataUrl: '@Url.Action("DesertSelect", "MetGrid")'
                }

            },
            {
                name: 'wnerName', index: 'wnerName', align: 'center', width: 90,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, edittype: 'text'

            },
            {
                name: 'MetDateInstall', index: 'MetDateInstall', align: 'center', width: 170,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            },
            {
                name: 'Emplacement', index: 'Emplacement', align: 'center', width: 90,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: true, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            },


            {
                name: 'WarrantyStartDate', index: 'WarrantyStartDate', align: 'center', width: 170,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            },
            {
                name: 'WarrantyEndDate', index: 'WarrantyEndDate', align: 'center', width: 170,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, edittype: 'text'

            },
            {
                name: 'CelOwner', index: 'CelOwner', align: 'center', width: 70,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: true, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            }, {
                name: 'CityID_FK', index: 'CityID_FK', align: 'center', width: 80,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: true, edittype: 'select',
                editoptions: {
                    dataUrl: '@Url.Action("CitySelect", "MeterGrid")'

                }

            },
            {
                name: 'UserIDCreate_FK', index: 'UserIDCreate_FK', align: 'center', width: 80,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, editoptions: { readonly: 'readonly' }

            },
            {
                name: 'UserIDChange_FK', index: 'UserIDChange_FK', align: 'center', width: 80,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: false, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            },
            {
                name: 'MetDateCreate', index: 'MetDateCreate', align: 'center', width: 170,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                editable: true, editoptions: { readonly: 'readonly' }

            },
            {
                name: 'MetDateChange', index: 'MetDateChange', align: 'center', width: 170,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: false, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            },
            {
                name: 'SettingID_FK', index: 'SettingID_FK', align: 'center', width: 80,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: true, edittype: 'select',
                editoptions: {
                    dataUrl: '@Url.Action("SettingSelect", "MeterGrid")'
                }

            },
            {
                name: 'Metitle', index: 'Metitle', align: 'center', width: 90,
                //formatter: formatNumber,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: true, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            },
              {
                  name: 'Longitude', index: 'Longitude', align: 'center', width: 70,
                  search: true, stype: 'text', searchoptions: { sopt: searchOptions },
                  editable: true, edittype: 'text',
                  editoptions: {
                      maxlength: 40
                  }

              },
            {
                name: 'Latitude', index: 'Latitude', align: 'center', width: 70,
                search: true, stype: 'text', searchoptions: { sopt: searchOptions },

                editable: true, edittype: 'text',
                editoptions: {
                    maxlength: 40
                }

            },

            {
                name: 'myac', width: 50, fixed: true, sortable: false, search: false,
                resize: false, formatter: 'actions',
                formatoptions: {
                    keys: true
                }
            }

            ],
            //pager for grid
            pager: $('#pager'),
            toppager: true,
            //number of rows per page
            rowNum: 10,
            rowList: [10, 20, 50, 100],
            //initial sorting column
            sortname: 'MetID',
            //initial sorting direction
            sortorder: 'desc',
            //we want to display total records count
            viewrecords: true,
            altRows: true,
            shrinkToFit: false,
            width: '900',
            height: 'auto',
            hidegrid: false,
            direction: "rtl",
            gridview: true,
            rownumbers: true,
            multiselect: true,
            footerrow: true,
            //loadonce:true,
            //userDataOnFooter: true,
            loadComplete: function () {
                //change alternate rows color
                $("tr.jqgrow:odd").css("background", "#E0E0E0");

            },
            loadError: function (xhr, st, err) {
                jQuery("#rsperror").html("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText);
            }


        })

        //jQuery("#list").jqGrid('filterToolbar', { searchOperators: true })

                .jqGrid('navGrid', "#pager",

                    { cloneToTop: true, add: false, edit: false, del: false },
                {},  // default settings for edit
                {},  // default settings for add
                {},  // delete instead that del:false we need this
                {
                    // search options
                    multipleSearch: true,
                    closeOnEscape: true,
                    closeAfterSearch: true,
                    ignoreCase: true
                })

                .jqGrid('navButtonAdd', '#pager',
                {
                    caption: "", title: "Reorder Columns",
                    onClickButton: function () {
                        jQuery("#list").jqGrid('columnChooser');
                    }
                })

            .jqGrid('navButtonAdd', '#pager', {
                caption: "pdf", buttonicon: "ui-icon-print", title: "pdf",
                onClickButton: function () {
                    $("#list").jqGrid('excelExport', { url: '@Url.Action("ReadCommand", "MetGrid")' });
                }
            })

                    .jqGrid('navButtonAdd', '#pager',
                            {
                                caption: "FF", buttonicon: "ui-icon-signal-diag", title: "FF",
                                onClickButton: function () {

                                    var selRow = jQuery("#list").jqGrid('getGridParam', 'selarrrow');  //get selected rows
                                    //var selRow = jQuery('#list').getGridParam(rowKey); //get selected rows

                                    if (selRow == 0) {
                                        // display error message because no row is selected
                                        $.jgrid.viewModal("#" + 'alertmod_' + this.p.id,
                                            { gbox: "#gbox_" + $.jgrid.jqID(this.p.id), jqm: true });
                                        $("#jqg_alrt").focus();
                                    }
                                    else {

                                        var dataToSend = JSON.stringify(selRow)

                                        $.ajax({
                                            url: '@Url.Action("Index", "AddSMS")' + '?cbChecked=' + $("input.myMultiSearch").is(":checked"),
                                            type: 'POST',
                                            contentType: 'application/json; charset=utf-8',
                                            data: dataToSend,
                                            dataType: 'json',
                                            success: function (result) {
                                                alert('success');
                                            }
                                        });
                                    }
                                }
                            })
        $("#pager_left table.navtable tbody tr").append( // here 'pager' part or #pager_left is the id of the pager
'<td><div><input type="checkbox" class="myMultiSearch" id="WithSetting" name="setting"/>setting</div></td>');



        function toolbarSearching() {
            $('#list').filterToolbar({
                groupOp: 'OR',
                defaultSearch: "cn",
                autosearch: true,
                searchOnEnter: true,
                searchOperators: true, //
                stringResult: true // 
            });
        };
        function singleSearching() {
            $('#list').searchGrid({
                multipleSearch: true,
                closeAfterSearch: true
            });

            function advancedSearching() {
                $('#list').searchGrid({
                    multipleSearch: true,
                    closeAfterSearch: true
                });
            };
        }
    })

</script>

0 个答案:

没有答案