-
22 Apr 2011 9:34 AM #1
grid column header menu - sort columns alphabetically
grid column header menu - sort columns alphabetically
Hi,
In my grid I have many columns most of which are not shown by default.
When making a column visible it would be easier to find the column in the header menu if I could order the list alphabetically (I do not want to change the order in which they appear in the grid, just sort the column list).
Could somebody tell me how to do that?
Thanks for the help.
SWK
-
23 Apr 2011 12:15 PM #2
See the code below.
I searched for "enableHdMenu" in the ext sources, found a reference in GridView to this.colMenu, then found the method beforeColMenuShow in which the column menu items are created.
You can always replace such a method with Ext.override.
You need to re-examine each overriden method whenever you upgrade ExtJS to a new version, though!
This is tested with ExtJS 3.2.2
PHP Code:Ext.override(Ext.grid.GridView, {
beforeColMenuShow : function() {
// Copy necessary data for the column items to an array
var cm = this.cm, colCount = cm.getColumnCount();
var sortedColumns = new Ext.util.MixedCollection();
for (var i = 0; i < colCount; i++) {
if (cm.config[i].hideable !== false) {
var columnId = cm.getColumnId(i);
sortedColumns.add(columnId,
{
id: columnId,
header: cm.getColumnHeader(i),
isHidden: cm.isHidden(i)
});
}
}
// Sort the column data by column header texts
sortedColumns.sort('ASC',
function(a, b){
var headerA = a.header.toLocaleLowerCase();
var headerB = b.header.toLocaleLowerCase();
return headerA.localeCompare(headerB)
});
this.colMenu.removeAll();
// finally create the menu items from the sorted column data
sortedColumns.each(function(columnData) {
this.colMenu.add(new Ext.menu.CheckItem({
itemId: 'col-' + columnData.id,
text: columnData.header,
checked: !columnData.isHidden,
hideOnClick:false
}));
}, this);
}
});
ExtJS 4 plugins:
varheaders - short/normal/long column header
clearbutton - mouseover clear button in text field
Blog: fit4dev
ExtJS User Group Hamburg
-
25 Apr 2011 1:40 PM #3
wow,
many thanks for this, I will try it when I return after Eastern.
Thanks again.
SWK
-
8 Nov 2011 2:44 AM #4
hi,
this works for me with Ext 3.4
I have added a short function to handle accented characters better (for my purpose).
Many thanks for the help.Code:String.prototype.strip = function() { var translate_re = /[ŠšĐđŽžČčĆćÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕüÜűőŐŰ]/g; var translate = { 'Š':'S', 'š':'s', 'Đ':'Dj', 'đ':'dj', 'Ž':'Z', 'ž':'z', 'Č':'C', 'č':'c', 'Ć':'C', 'ć':'c', 'À':'A', 'Á':'A', 'Â':'A', 'Ã':'A', 'Ä':'A', 'Å':'A', 'Æ':'A', 'Ç':'C', 'È':'E', 'É':'E', 'Ê':'E', 'Ë':'E', 'Ì':'I', 'Í':'I', 'Î':'I', 'Ï':'I', 'Ñ':'N', 'Ò':'O', 'Ó':'O', 'Ô':'O', 'Õ':'O', 'Ö':'O', 'Ø':'O', 'Ù':'U', 'Ú':'U', 'Û':'U', 'Ü':'U', 'Ý':'Y', 'Þ':'B', 'ß':'Ss', 'à':'a', 'á':'a', 'â':'a', 'ã':'a', 'ä':'a', 'å':'a', 'æ':'a', 'ç':'c', 'è':'e', 'é':'e', 'ê':'e', 'ë':'e', 'ì':'i', 'í':'i', 'î':'i', 'ï':'i', 'ð':'o', 'ñ':'n', 'ò':'o', 'ó':'o', 'ô':'o', 'õ':'o', 'ö':'o', 'ø':'o', 'ù':'u', 'ú':'u', 'û':'u', 'ý':'y', 'ý':'y', 'þ':'b', 'ÿ':'y', 'Ŕ':'R', 'ŕ':'r', 'ü':'u', 'Ü':'U', 'ű':'u', 'ő':'o', 'Ő':'o', 'Ű':'U' }; return (this.replace(translate_re, function(match){ return translate[match];}) ); }; ..... than in the override ......... function(a, b){ var headerA = a.header.toLocaleLowerCase().strip(); var headerB = b.header.toLocaleLowerCase().strip(); return headerA.localeCompare(headerB) }); .......
SWK
Similar Threads
-
GXT Grid - How can i hide the grid column from the Header Menu columns drop down
By gxtyas in forum Ext GWT: DiscussionReplies: 4Last Post: 8 Aug 2012, 12:11 AM -
GXT Grid, How to sort the column menu Header Item
By gxtyas in forum Ext GWT: DiscussionReplies: 1Last Post: 14 Oct 2010, 9:20 AM -
Grid Header Columns Not Resizing After Sort
By bgoodin in forum Ext GWT: DiscussionReplies: 1Last Post: 23 Sep 2009, 10:57 AM -
Can you change grid column header menu for individual columns?
By NegrilLover in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 26 Jun 2008, 5:38 PM


Reply With Quote