0

How can I get all of the rows or IDs that are not removed after a user uses the filter toolbar?

My jqgrid:

enter image description here

I use :

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

But this code get 3 of row and I want all row of other pages selected!!!

javascript code:

   <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>
mahdis dezfouli
  • 173
  • 3
  • 19
  • use `loadOnce:true` when using `json` to create grid. – Jai Jul 28 '15 at 07:19
  • @Jai Thanks for reply. But this resolve did not work. and got 3 row – mahdis dezfouli Jul 28 '15 at 07:40
  • You should describe more clear what you do and what you want to implement. You wrote "... get all of the rows...that are not *removed*". What you mean with "removed" rows? You wrote about selection of multiple rows and one can see chechboxes on the right size of the grid. Do you use `direction: "rtl"` or you use free jqGrid 4.9 with `multiselectPosition: "right"` option? **which fork of jqGrid and in which version you use?** You used [MvcJqGrid](http://stackoverflow.com/tags/mvcjqgrid/info) tag which mean that you use special product which are based on jqGrid. Is it really so? – Oleg Jul 28 '15 at 09:28
  • You should understand that the current implementation of jqGrid hold selection **only inside of one page** which is displayed. Every reloading of the grid, filtering, changing the page and so on resets typically previously selected rows. There are some exception, but you should use additional options. In any way you should post JavaScript code which you use instead of just posting the picture. – Oleg Jul 28 '15 at 09:31
  • @Oleg I mean of"... get all of the rows...that are not removed", data after search and show in grid. I got Jqgrid [link](https://github.com/tonytomov/jqGrid/releases). but don't remember what version. I use directin: rtl. and multiselect: true. I want when i Select checkbox on header, All of chechkboxes on all pages selected. I mean all rows on page 1 and other pages. – mahdis dezfouli Jul 28 '15 at 10:08
  • @Oleg my jqgrid hold selection of multiple page after reloading and filtering. and reset previously selected rows. but when i selected all on header and click one button on footer, i want selected all rows even all row of other page. I don't know you Understand my Problem or no? – mahdis dezfouli Jul 28 '15 at 10:32
  • **all pages** can exist **only on the server** and jqGrid have no information about it. jqGrid have only manimally 10 rows of the currect page (see `rowNum`). It have no information about all rowids in the grid. You have to managed the whole set of selected rows yourself. I don't see any code which would hold selection of multiple page after reloading and filtering. You have to save ids of selected rows or the information that you want to select *all rows* now. You should restore selection inside of `loadComplete` for example. – Oleg Jul 28 '15 at 10:40
  • See [the old answer](http://stackoverflow.com/a/8172723/315935) or [this one](http://stackoverflow.com/a/8138980/315935). Another possibility are described [here](http://stackoverflow.com/a/8436273/315935), [here](http://stackoverflow.com/a/8547852/315935) and [here](http://stackoverflow.com/a/31663268/315935). One shows how to save state of the grid, inclusive ids of selected rows and restore the state after reloading of the page. – Oleg Jul 28 '15 at 10:44

0 Answers0