0

I have added the jqGrid on bootstrap modal and shown users list in the jqgrid. On click of a button I am opening modal and the data is displayed. Till this its working fine. But whenever I am trying to use jqGrid Search functionality its not working. The search textbox, search parameters all are disabled and not able to search. But when I have added the jgGrid on regular page/view, there search is working fine.

Below is my jqGrid

jQuery("#jqgrid1").jqGrid({

            url: '@Url.Action("GetUserList", "Class")',
            datatype: "Json",
            height: 'auto',

            colNames: ['Id', '@objLocalizer["Class_FirstName_GridCol"]', '@objLocalizer["Class_LastName_GridCol"]', '@objLocalizer["Class_Email_GridCol"]'],
            colModel: [{
                name: 'Id',
                index: 'Id',
                sortable: false,
                hidden: true
            },
                {
                    name: 'FirstName',
                    index: 'FirstName',
                    sortable: true,
                    sorttype: 'text',
                },
                {
                    name: 'LastName',
                    index: 'LastName',
                    sortable: true,
                    sorttype: 'text',

                },
                {
                    name: 'Email',
                    index: 'Email',
                    sortable: true,
                    sorttype: 'text',

                }],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#pjqgrid1',
            sortname: 'id',
            toolbarfilter: true,
            viewrecords: true,
            sortorder: "asc",
            search: true,
            refresh: true,
            loadonce: true,
            ignoreCase: true,
            gridComplete: function () {
                var ids = jQuery("#jqgrid1").jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) {
                    var cl = ids[i];
                    be = "<button class='btn btn-xs btn-default' data-original-title='Edit Row' onclick=\"jQuery('#jqgrid1').editRow('" + cl + "');\"><i class='fa fa-pencil'></i></button>";
                    se = "<button class='btn btn-xs btn-default' data-original-title='Save Row' onclick=\"jQuery('#jqgrid1').saveRow('" + cl + "');\"><i class='fa fa-save'></i></button>";
                    ca = "<button class='btn btn-xs btn-default' data-original-title='Cancel' onclick=\"jQuery('#jqgrid1').restoreRow('" + cl + "');\"><i class='fa fa-times'></i></button>";

                    jQuery("#jqgrid1").jqGrid('setRowData', ids[i], {
                        act: be + se + ca
                    });
                }
            },
            editurl: "",
            caption: '@objLocalizer["Class_Users_GridHeader"]',
            multiselect: true,
            autowidth: true,
            multipleSearch: true,
            multipleGroup: true,
            showQuery: true,
            onSelectRow: updateIdsOfSelectedRows,

            onSelectAll: function (aRowids, isSelected) {

                var i, count, id;
                for (i = 0, count = aRowids.length; i < count; i++) {
                    id = aRowids[i];
                    updateIdsOfSelectedRows(id, isSelected);
                }
            },

            loadComplete: function () {

                var $this = $(this), i, count;
                for (i = 0, count = idsOfSelectedRows.length; i < count; i++) {
                    $this.jqGrid('setSelection', idsOfSelectedRows[i], false);

                }
            }

        });
        jQuery("#jqgrid1").jqGrid('navGrid', "#pjqgrid1", {
            edit: false,
            add: false,
            del: true
        });

        jQuery('#jqgrid1').jqGrid('setGridWidth', '582');



        // remove classes
        $(".ui-jqgrid").removeClass("ui-widget ui-widget-content");
        $(".ui-jqgrid-view").children().removeClass("ui-widget-header ui-state-default");
        $(".ui-jqgrid-labels, .ui-search-toolbar").children().removeClass("ui-state-default ui-th-column ui-th-ltr");
        $(".ui-jqgrid-pager").removeClass("ui-state-default");
        $(".ui-jqgrid").removeClass("ui-widget-content");

        // add classes
        $(".ui-jqgrid-htable").addClass("table table-bordered table-hover");
        $(".ui-jqgrid-btable").addClass("table table-bordered table-striped");

        $(".ui-pg-div").removeClass().addClass("btn btn-sm btn-primary");
        //$(".ui-icon.ui-icon-plus").removeClass().addClass("fa fa-plus");
        $(".ui-icon.ui-icon-pencil").removeClass().removeClass("fa fa-pencil");
        $(".ui-icon.ui-icon-trash").removeClass().addClass("fa fa-trash-o");
        $(".ui-icon.ui-icon-search").removeClass().addClass("fa fa-search");
        $(".ui-icon.ui-icon-refresh").removeClass().addClass("fa fa-refresh");
        $(".ui-icon.ui-icon-disk").removeClass().addClass("fa fa-save").parent(".btn-primary").removeClass("btn-primary").addClass("btn-success");
        $(".ui-icon.ui-icon-cancel").removeClass().addClass("fa fa-times").parent(".btn-primary").removeClass("btn-primary").addClass("btn-danger");

        $(".ui-icon.ui-icon-seek-prev").wrap("<div class='btn btn-sm btn-default'></div>");
        $(".ui-icon.ui-icon-seek-prev").removeClass().addClass("fa fa-backward");

        $(".ui-icon.ui-icon-seek-first").wrap("<div class='btn btn-sm btn-default'></div>");
        $(".ui-icon.ui-icon-seek-first").removeClass().addClass("fa fa-fast-backward");

        $(".ui-icon.ui-icon-seek-next").wrap("<div class='btn btn-sm btn-default'></div>");
        $(".ui-icon.ui-icon-seek-next").removeClass().addClass("fa fa-forward");

        $(".ui-icon.ui-icon-seek-end").wrap("<div class='btn btn-sm btn-default'></div>");
        $(".ui-icon.ui-icon-seek-end").removeClass().addClass("fa fa-fast-forward");



        var bottomPagerDiv = $("div#pjqgrid1")[0];
        //$("#refresh_jqgrid1", bottomPagerDiv).remove();
        $("#jqgrid1_ilcancel", bottomPagerDiv).remove();
        $("#jqgrid1_ilsave", bottomPagerDiv).remove();
        $("#del_jqgrid1", bottomPagerDiv).remove();
        $("#jqgrid1_iledit", bottomPagerDiv).remove();
        $("#jqgrid1_ilsave", bottomPagerDiv).remove();
        //$("#search_jqgrid1", bottomPagerDiv).remove();


        $('#refresh_jqgrid1').attr('title', '@objLocalizer["refreshModal_jqgrid"]');
        $('#search_jqgrid1').attr('title', '@objLocalizer["searchModal_jqgrid"]');

The grid binding is done in document.Ready function.

Any help on this appreciated !

XamDev
  • 3,377
  • 12
  • 58
  • 97
  • 1
    You use relatively strange options of jqGrid. **Which version of jqGrid you use (can use) and from which fork of jqGrid** ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7)? You wrote that you have some problems *only in case of usage it inside of Bootstrap modal*, but the code not. It's better that you provide the demo (in JSFiddle for example), which reproduce the problem, which you want to report. One can modify your demo to fix the problem. – Oleg Jan 11 '17 at 10:44
  • @Oleg We are using version 4.5.3. Actually we directly not using the jqGrid library. We have opted for ready made available template/theme and we are using there css, js files. But this will make the difference ? We are using this http://192.241.236.31/themes/preview/smartadmin/1.8.x/ajax/index.html#ajax/jqgrid.html theme – XamDev Jan 12 '17 at 10:04
  • 2
    jqGrid 4.5.3 is retro version, which is out of support since a lot of time. [Free jqGrid](https://github.com/free-jqgrid/jqGrid) is compatible to 4.5.3, but it allows dramatically reduce your code because it supports Bootstrap and Font . See [here](https://free-jqgrid.github.io/getting-started/index.html#bootstrap) and [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/Using-Font-Awesome-in-free-jqGrid-4.8). One need just include the CSS files and add the options `iconSet: "fontAwesome"` and `guiStyle: "bootstrap"`. Cancel button, which you use, has sense only after starting editing – Oleg Jan 12 '17 at 10:11
  • 1
    If you do need some custom icons then the `formatter: "actions"` (or better, `template: "actions"`) allows to use `actionsNavOptions` option. See [the demo](http://www.ok-soft-gmbh.com/jqGrid/OK/CustomActionButton.htm), described in [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/Enhancement-of-formatter:%22actions%22), and [another one](http://www.ok-soft-gmbh.com/jqGrid/OK/CustomActionButton1.htm), described in [the answer](http://stackoverflow.com/a/29735149/315935). Thus I recommend you just upgrade to free jqGrid 4.13.6 instead of using 3.5 years old version 4.5.3. – Oleg Jan 12 '17 at 10:15
  • 1
    I see that you use `loadonce: true`, then `forceClientSorting: true` could be interesting for you. It allows to sort/filter the data *locally* instead of sorting it on the server initially. You use `multiselect: true`, then other new option `multiPageSelection: true` could be helpful for you. [The demo](http://www.ok-soft-gmbh.com/jqGrid/OK/multiPageSelection.htm) described in [the answer](http://stackoverflow.com/a/33021115/315935) demonstrate the feature. It allows to preselect some rows on loading and to hold selection over the paging/sorting and filtering. Just try to sort or paging ... – Oleg Jan 12 '17 at 10:24
  • @Oleg Thanks for the help ! – XamDev Jan 13 '17 at 04:04

1 Answers1

0

Remove loadonce from your jqgrid

Jignesh Hirpara
  • 135
  • 1
  • 5