Lolly
Lolly

Reputation: 36422

jqgrid custom button column in load complete

I am using Jqgrid with a custom button column. I using jqgrid's load complete method to populate the button. Below the code I use in load complete.

var grid =  $("#grid"),
             iCol = getColumnIndexByName(grid,'custom'); // 'custom' - name of the actions column
             grid.children("tbody")
                    .children("tr.jqgrow")
                    .children("td:nth-child("+(iCol+1)+")")
                    .each(function() {
                     $("<div>",
                            {
                                title: "button1",
                                mouseover: function() {
                                    $(this).addClass('ui-state-hover');
                                },
                                mouseout: function() {
                                    $(this).removeClass('ui-state-hover');
                                },
                                click: 
                                handle your click function here
                                }
                          ).css({"margin-left": "5px", float:"left"})
                           .addClass("ui-pg-div ui-inline-save")
                           .attr('id',"customId")
                           .append('<span class="ui-button-icon-primary ui-icon ui-icon-disk"></span>')
                           .appendTo($(this).children("div")); 
                )};

var getColumnIndexByName = function(grid,columnName) {
                var cm = grid.jqGrid('getGridParam','colModel'), i=0,l=cm.length;
                for (; i<l; i+=1) {
                    if (cm[i].name===columnName) {
                        return i; // return the index
                    }
                }
                return -1;
            };

It displays buttons in all the rows. But I want to get it displayed only in few rows based on the value from first and second column. Is there any easy way where i can get the first and second column values or I need to iterate again over "tbody" and retrieve the results ? Please help me out.

Upvotes: 0

Views: 1105

Answers (1)

ffffff01
ffffff01

Reputation: 5238

You should check out custom formatters.

In a column you can define a formatter in the colmodel that triggers for each row of the grid. Then you can do the following:

function formatterName(cellvalue, rowid, rowObject)
{
    if(rowObject[1] == "YourValue" && rowObject[2] == "YourValue"){ // index for choosing which column to check
         // run code for displaying buttons in the columns that matches your criteria
    }
}

Upvotes: 1

Related Questions