Adding a custom icon to jqgrid action column with onclick event

Naveen Reddy picture Naveen Reddy · Sep 18, 2013 · Viewed 11.8k times · Source

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"));
                });
            }

Answer

Oleg picture Oleg · Sep 18, 2013

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.