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();
}
}
 
Share and Enjoy:
  • Digg
  • Technorati
  • Google Bookmarks
  • del.icio.us
  • Facebook
  • StumbleUpon
This entry was posted on Friday, February 20th, 2009 at 6:08 am and is filed under JavaScript, Software Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One comment

 1 

Hey There, I have to say, that I lover your blog.
Please go on like that and don’t stop posting. I hope this comment motivates you to do so, smile
regards, kali

May 12th, 2009 at 5:20 am

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment