Question

Here is a demo to add a custom icon in Actions column of jQgrid. In my case if I add 3 rows gridComplete is called 3 times. So I am getting 3 custom Icons in 1st row , 2 in 2nd row and 1 in 3rd row. Is there anyway we can add custom Icons based on Row and Column???

gridComplete: function () {
                var iCol = getColumnIndexByName(grid, 'act');
                $(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")")
                    .each(function() {
                        $("<div>", {
                            title: "Custom",
                            mouseover: function() {
                                $(this).addClass('ui-state-hover');
                            },
                            mouseout: function() {
                                $(this).removeClass('ui-state-hover');
                            },
                            click: function(e) {
                                alert("'Custom' button is clicked in the rowis="+
                                    $(e.target).closest("tr.jqgrow").attr("id") +" !");
                            }
                        }
                      ).css({"margin-right": "5px", float: "left", cursor: "pointer"})
                       .addClass("ui-pg-div ui-inline-custom")
                       .append('<span class="ui-icon ui-icon-document"></span>')
                       .prependTo($(this).children("div"));
                });
            }
Was it helpful?

Solution

Look at the modified demo created for the answer. It uses jqGrid 4.4.4, but the same code (see the demo) works for jqGrid 4.5.2 too.

OTHER TIPS

I think there is an error in the line:

$(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")")

should be

$(this).find("tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")")

(removing the ">" before the tbody)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top