Archive for February, 2009

20
Feb

more jqGrid patterns

   Posted by: admin    in JavaScript, Software Development

I have been using jqGrid a lot, and thought I’d post a few of the solutions / hacks I came up with that were useful:

/* replace grid values */
    ,loadComplete: function(){
        var ids = jQuery("#grid").getDataIDs();
        /* for each row loaded */
        for(var i=0;i<ids.length;i++){
            var cl = ids[i];
            /* get the row data, this works best when you have to do this for multiple columns, otherwise you might use getCell  */
            var objRowData = jQuery("#grid").getRowData(cl);
            /* for each column, give it a replacement or function that modifies the value */
            jQuery("#grid").setRowData(cl,{
                ntlm:renderCheckmark(objRowData.ntlmHidden)
            });
        }
    }

/* Allow resort of rows. */    
    ,loadComplete: function() {
        jQuery("#grid").tableDnD({
            onDrop:function(objTable,objRow) {
                /* get the resulting order */
                var rows = jQuery(‘#grid’).getDataIDs();
            }
        }
    }
   
/* Add something in the middle of the navbar where the inserted position is relative to the "eq(1)" */
jQuery(‘#gridPager td.nav-button:eq(1)’).after(‘html stuff to add in’);

/* Use the nav bar for buttons but hide the pager. CSS */
#grid  #first, #grid  #prev, #grid  input.selbox, #grid  #sp_1, #grid  #sp_2, #grid  #next, #grid  #last{display:none;}
 

Only show the pager when there are enough rows to use it.

,loadComplete: function(){
        /* Dynamically show the pager if it’s needed */
        if(jQuery("#tableGroup").getGridParam("records") > jQuery("#tableGroup").getGridParam("rowNum")){
            jQuery(‘#tableGroupPager’).find(‘#first, #prev, input.selbox, #sp_1, #sp_2, #next, #last’).show();
        }else{
            jQuery(‘#tableGroupPager’).find(‘#first, #prev, input.selbox, #sp_1, #sp_2, #next, #last’).hide();
}
}