0

I researched many post but i have still seen my error.

gridComplete : function() {
                            var ids = jQuery("#jqgrid").jqGrid('getDataIDs');
                            for (var i = 0; i < ids.length; i++) {
                                var cl = ids[i];
                                var rowData = jQuery('#jqgrid').jqGrid ('getRowData', cl);
                                be = "<button class='btn btn-xs btn-default' data-original-title='Edit Row' onclick=\"jQuery('#jqgrid').editRow('" + cl + "');\"><i class='fa fa-pencil'></i></button>";
                                se = "<button class='btn btn-xs btn-default' data-original-title='Save Row' onclick=\"actionSaveRow('" + cl + "');\"><i class='fa fa-save'></i></button>";
                                ca = "<button class='btn btn-xs btn-default' data-original-title='Cancel' onclick=\"jQuery('#jqgrid').restoreRow('" + cl + "');\"><i class='fa fa-times'></i></button>";

                                if (rowData.active == "Active") {
                                    fa = "<a class='btnActive' href='#' data-id='" + cl + "' data-value='Active'><i class='label label-success'>Active</i></a>";
                                }
                                else {
                                    fa = "<a class='btnActive' href='#' data-id='" + cl + "' data-value='Lock'><i class='label label-success'>Lock</i></a>";    
                                }
                                jQuery("#jqgrid").jqGrid('setRowData', ids[i], {
                                    act : be + se + ca,
                                    active : fa
                                });
                            }
                        }

My buttons in act col show well, but my link in active col does not show. I checked data json return is good. My browser does not show any error. Please talk to me where my code is error ?

Many thanks.

Ryan Tran
  • 467
  • 6
  • 16
  • 1
    Sorry, but it's an example of very bad code. The usage of `setRowData` in the loop is very slow. One see it clear in case of large number of rows. There are exist `formatter: "actions"` which do already all what you want. Which fork of jqGrid and in which version you use. [Free jqGrid](https://github.com/free-jqgrid/jqGrid) have support of Font Awesome (see [the wiki](https://github.com/free-jqgrid/jqGrid/wiki/Using-Font-Awesome-in-free-jqGrid-4.8)) and you can just define column as `{name: "act", template: "actions"}` like [the demo](http://www.ok-soft-gmbh.com/jqGrid/OK/FontAwesome4.htm). – Oleg May 24 '15 at 07:40
  • Thank you for your reply, I checked my code and found my problem is "formatter". I don't think "The usage of setRowData in the loop is very slow" because data is loaded by ajax method. – Ryan Tran May 28 '15 at 09:46
  • The loop with `setRowData` is slow independent from the source of data (Ajax or not). If you have for example 1000 rows in the grid, you make the loop over the 1000 rows and modify every row. You though that the complexity of the job is 1000. It's wrong if you use `setRowData`. The reason is the following. If you modify **one** item of grid then it can change position of other elements already existing on the page (below of modified item). So by changing of one item web browser recalculate position of all 1000 elements. So the web browser will do 1000*1000 recalculations. – Oleg May 28 '15 at 10:09
  • 1
    On the other side you can use custom formatter how I suggest you. In the case you will set correct value for `act` and `active` column **directly during building of HTML fragments** which will be placed on the page. jqGrid collect all the values for the body in one array. After that it set **once** `innerHTML` of the grid body (`tbody`). The web browser parses the HTML string and set it at once. Because of that it works very quickly. In many cases the rebuilding of the whole grid can take the time close to 2-3 modifications of cells using `setRowData` because of the recalculation problems. – Oleg May 28 '15 at 10:14
  • See more information in [the article](https://developers.google.com/speed/articles/reflow) which I reference in [the answer](http://stackoverflow.com/a/12519858/315935) – Oleg May 28 '15 at 10:16

1 Answers1

0

Show us your colModel. Try declaring fa variable above if else block. I think it doesn't understand what fa is.

Thiêm
  • 155
  • 8