Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Discussion about modifications i made to the "columnChooser" method.
07/02/2013
04:05
Avatar
nelsonm
Michigan, USA
Member
Members
Forum Posts: 106
Member Since:
20/08/2011
sp_UserOfflineSmall Offline

First of all, I'm greatfull that a way to dynamically sort and hide/show columns via the "columnChooser" method exists.

However, it seems a bit awkward and incomplete in it's functionality in the "apply_perm" option function within the "columnChooser" method.

1. if you don't use the "done" option, the method remaps the columns using the default jqgrid remapColumns method attached to the "done" option in the "columnChooser" method extended options.  If you do use the "done", you have to execute the jqgrid remapColumns method manually in a user defined "done" callback function.  However, hiding and showing columns is always managed within the "apply_perm" option function regardless of whether a user defined "done" callback function is defined.  It seems to me that the remapping and visibility of the columns should always be handled within the "apply_perm" option function regardless of whether a user defined "done" callback function is defined.

2. the "columnChooser" method always makes the permutation array available as a parameter of the user defined "done" callback function.  This is most usefull for storing and retrieving the column order via SQL.  However, there is no array available that contains the visibility of the columns to use in storing and retrieving the column visibility via SQL.

When i reload my site, i find it usefull to be able to retrieve and restore both the permutation and visibility of all jqGRID columns.

So, i made a few modifications to the columnChooser's "apply_perm" option function to make make its functionallity more consistant and usefull.

Here are the modifications i made (in black).  Your comments are welcome. (It would also be nice if columns in the hidden select list on columnChooser could be added back to the visible select list in the same location it was removed from in the visible select list. TBD)

"apply_perm" : function() {

   $('option',select).each(function() {

      if (this.selected) {

         self.jqGrid("showCol", colModel[this.value].name);

      } else {

         self.jqGrid("hideCol", colModel[this.value].name);

      }

   });

   var visi = [];

   $.each(colModel, function(i){visi.push(!this.hidden);});

   var perm = [];

   //fixedCols.slice(0);

   $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); });

   $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });

   $.each(colMap, function() {

      var ti = parseInt(this,10);

      perm = insert(perm,ti,ti);

   });

   self.jqGrid("remapColumns", perm, true);

   if (opts.done) {

      opts.done.call(self, perm, visi);

   }

},

Now the user defined callback function has access to both the permutation and visibility arrays available to store and restore via SQL as follows:

function setGridState(gid,pid,caption,title){

   // setup print button in the grid top navigation bar.

   $('#'+gid).jqGrid('navSeparatorAdd', '#'+gid+'_toppager_left', {sepclass :'ui-separator'});

   $('#'+gid).jqGrid('navButtonAdd', '#'+gid+'_toppager_left', {caption: caption, title: title, position: 'last', buttonicon: 'ui-icon-wrench', onClickButton : function (){$('#'+gid).jqGrid('columnChooser',{done: done});/* HideColumns('#colchooser_',gid); */}});

   // OK or Cancel button are clicked.

   var done = function(perm,visi){

      // OK was clicked.

      if (perm){

         // maintain proper grid width.

         $('#'+gid).jqGrid('setGridWidth',SavedGridWidth[gid]);

         // save new column order and visability in database.

         SaveGridState(gid,perm,visi);

      }else{

         // we can do some action in case of "Cancel" button clicked

      }

   }

}

What do you all think?

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
39 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information