0

Hi I am using jQGrid free version 4.1.2 and I am facing problem on loading tree grid. I am storing data in an array object and loading that in tree grid. When I am loading a small amount of data it is working fine but when the data is more of quantity it is taking to much time in rendering (setting the data in columns). The length of my array object is around 1700.

I am using below prperties to load the grid

 grid.jqGrid({
            datatype: "jsonstring",
            datastr: mydata,  //array object
            colNames: scopes.gridheadercolumns, //passed externally
            colModel: scopes.gridcolumns,      
            height: height, //passed externally
            gridview: true,
            loadonce: false,
            viewrecords: viewrecordslist,
            rowList: rowlists,
            rowNum: rowNum,
            multiSort: true,
            ignoreCase: true,
            grouping: gpenable,
            sortorder: sortorder,  //passed externally
            autowidth: true,
            sortable: false,
            pager: "#" + pagerid,   //passed externally
            treeGrid: true,
            treeGridModel: 'adjacency',
            treedatatype: "local",
            ExpandColumn: 'name',
            sortname: 'name',
            jsonReader: {
                repeatitems: false,
                root: function (obj) { return obj; },
                page: function () { return 1; },
                total: function () { return 1; },
                records: function (obj) { return obj.length; },
                expanded_field: "true"
            },
            loadComplete: function () {
                var ts = this;

                if (ts.p.reccount === 0) {
                    $(this).hide();
                    emptyMsgDiv.show();
                } else {
                    $(this).show();
                    emptyMsgDiv.hide();
                }

            }
        });

I have changed some of above properties like this

loadonce: true,
gridview: false,
treedatatype :"jsonstring" 

Here which property can I remove from the function to make it load faster or what else can I do to improve the performance is I need.

Also, this problem occur specifically in IE 11. Not in other browser.

Any help would be appreciated. Thanks

Edit : I forgot to include one point that grid also become considerably slow when we load it muliple times. How can we ensure that performance not degrade with multiple request.

Code for tdynamicLink Formatter -

Here the foramtoptions url and cellattr are not used.

Only I am applying a class to make it look as a link (I am just making text underline and cursor to pointer in that class) and calling function getPopup to open modal window

 if (formatter == "editLink") {

                    var subpopup = grid_row_data[j]._attr.popupid._value;
                    var xmlname = grid_row_data[j]._attr.popxml._value;
                    formatter= 'dynamicLink';
                    formoption= {
                            url: function (cellValue, rowId, rowData) {
                                return '/' + rowId + '?' + $.param({
                                tax: rowData.col_nigo,
                                invdate: rowData.col_igo_nigo,
                                closed: rowData.col_phireq
                            });
                        },
                        cellValue: function (cellValue, rowId, rowData) {
                            return  '<span class="pointer">' + cellValue + '</span>'; 
                            },
                        onClick: function (rowId, iRow, iCol, cellValue, e) {
                            $("#"+subpopup).css("display", "block");
                            $("#" + popupid).css("opacity", "0.99");
                            $scope.getPopup(rowId, iRow, iCol,gridid ,xmlname,rowId);                      
                        }
                    };
                    cellattr = function (rowId, cellValue, rawObject) {
                        var attribute = ' title="' + rawObject.name;
                        if (rawObject.closed) {
                            attribute += ' (closed)';
                        }
                        return attribute + '"';
                    };
            }
shv22
  • 680
  • 5
  • 28

1 Answers1

1

Sorry, but the most tricks which you use should have no value and the usage of treedatatype: "jsonstring" should be incorrect. TreeGrid reset many parameters during initialization, because some specific values are really required. See the lines of code for more details. For example, loadonce: true has some value only in case of loading the data from the server (datatype: "json" or datatype: "json") and not for TreeGrid. I recommend you remove many unused options to clean-up your code. The options gridview, loadonce, rowList, rowNum, grouping, sortable, treedatatype like the most of properties of jsonReader (or probably whole jsonReader) should be removed.

Now about your main problem. I see only two ways to improve performance of TreeGrid

  1. Upgrade to free jqGrid 4.10.0 from 4.1.2. It improves the performance of creating/loading the grid and essentially improves the performance of collapsing/expanding of nodes.
  2. Create and fill the hidden TreeGrid and then make it visible. You can place <table>, used for the grid, inside of the div. The div should have the width which corresponds the width of window. The div should be visible. You should get the width of the div using jQuery.width and to use teh value as the width value of jqGrid. Then you hide the div with respect of jQuery.hide. Now you can create TreeGrid, which will be not visible. Finally, you should make the outer div visible and the TreeGrid will be visible too.
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks for answer. There is one point I forgot to include when we do multiple operations in the grid it is becoming slow by time. Will upgrading to 4.10.0 help on this also? – shv22 Apr 09 '17 at 11:19
  • @shv22: You are welcome! I don't understand what you mean under "multiple operations in the grid". Which kind of operations you mean? In any way to test your code with free jqGrid 4.10.0 you will need just change the URLs from which you load jqGrid CSS and JS files. You need to load jqGrid files directly from CDN. See [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs). It's just changing of 3 lines of you HTML page. – Oleg Apr 09 '17 at 18:26
  • I think now everything working fine but it doesnt support property of dynamicLink...what can be alternative of this? – shv22 Apr 10 '17 at 05:23
  • Actually I just need to call a function each time leaf node is clicked on the tree grid...I just need to apply a class so that it would look like a link and on clicking cell I was calling a function which would further load a modal window above that...I have added my dynamicLink code in question – shv22 Apr 10 '17 at 05:42
  • @shv22: It seems, that you can just use extended formatter "showlink": `formatter: "showlink", formatoptions: { idName: null, addParam: function (options) { return "/" + encodeURIComponent(options.rowid) + "?" + $.param({ tax: options.rowData.col_nigo, invdate: options.rowData.col_igo_nigo, closed: options.rowData.col_phireq }; }, cellValue: function (options) { return '' + options.cellValue + ''; }, onClick: function (options) { alert("rowid=" + options.rowid + ", iCol=" + options.iCol + ", iRow=" + options.iRow + ", gridid=" + this.id); } }` – Oleg Apr 10 '17 at 09:27
  • @shv22: See [the wiki article](https://github.com/free-jqgrid/jqGrid/wiki/improvement-of-formatter:-%22showlink%22) for more details. – Oleg Apr 10 '17 at 09:27
  • I uesd the above formatter it is not working as expected. First it is giving error at formatoptions: if I am using formatoptions = it will work but then cellValue it is not app;ying css – shv22 Apr 10 '17 at 10:51
  • can I use beforeSelectRow in tree grid to apply class to leaf node? – shv22 Apr 10 '17 at 10:52
  • @shv22: Sorry, but I have to do my main job too. :-) Please, try yourself and prepare new question with the demo if you have some unclear questions. I don't understand what you trying to implement now. `beforeSelectRow` can be used as replacement of `onClick` of `formatter: "showlink"`. In many cases one can just use `classes` property of `colModel` to apply any CSS rules on the content of the column (like change the cursor, apply `text-decoration: underline` and so on). You can use `beforeSelectRow` to implement custom behavior on click inside of the column. – Oleg Apr 10 '17 at 11:05
  • sorry to trouble you so much...thanks for all your help...yes I am using beforeSelectRow to have a modal window...just need to figure out how to make it appear as link – shv22 Apr 10 '17 at 11:09
  • @shv22: Look at [here](http://stackoverflow.com/a/42601730/315935), [here](http://stackoverflow.com/a/40673839/315935), [here](http://stackoverflow.com/a/14537512/315935) or some other my answers, where `beforeSelectRow` are used. I hope it helps you. – Oleg Apr 10 '17 at 11:19