peter.riche
01-29-2008, 12:13 PM
Hi all,
And as my first message in here, I do thank ALL the team and EACH user contributing. It's a real pleasure to see what a wonderful work can be done within here. =D>
Now, here is my first kind of contribution. I came to the need of a "standard" GridPanel with quite usual "add, delete" buttons to manage a list of people. But I wasn't satisfied with the "paging" system because when I'm searching for somebody in the list (read "the grid"), I'm used to click on his name's first letter as in an address book. So I decided to put all the letters in the top toolbar where I thought it would be great! Here is what I did, first creating the "alphaTbar" items :
var alphaTbarItems = new Array();
for(var i = 65; i < 91; i++) { // JS char codes from (upper) A to Z
var myChar = String.fromCharCode(i); // get the letter from the char code
alphaTbarItems.push({ // add this vars to the array
text: myChar, // just the letter
id: 'alphaTbarItem' + myChar, // this button id will contain the letter
enableToggle: true, // only one will be pressed
toggleGroup: 'alphaTbarItems',
handler: function() { // when this button is pressed
if (this.pressed) { // if it is now in a "pressed" state (toggle is enabled)
myDataStore.load({ // reload the dataStore
params: { letter: this.text, } // passing the letter as parameter
});
} else myDataStore.load(); // if it is unpressed, reload the dataStore with full list
}
});
}
Then here is the GridPanel :
var myListGrid = new Ext.grid.GridPanel({
border: false,
store: myDataStore,
columns: [
{header: 'Name', width: 140, sortable: true, dataIndex: 'name'},
{header: 'Zip', width: 35, sortable: true, dataIndex: 'zip'},
{header: 'City', width: 90, sortable: true, dataIndex: 'city'},
{header: 'Phone', width: 50, sortable: true, dataIndex: 'phone'},
],
viewConfig: { forceFit: true, },
// only one toolbar can be passed inline
tbar: myActionButtonsTopToolbar, // this one has add/delete/refresh buttons
bbar: myInfoBottomToolbar,
});
Then, two things are needed : showing the GridPanel (mine is in a window) and loading the dataStore :
myWindow.show();
myDataStore.load();
myAlphaTbar = new Ext.Toolbar({
renderTo: myListGrid.tbar, // that one line did the job!!
items: myAlphaTbarItems, // use formerly created buttons
});
myListGrid.syncSize(); // don't do that and the toolbar may not appear!
I've modified it "live" for the forum, but that should work like that :
http://img252.imageshack.us/img252/492/notitlepl3.png
Some notes :
myWindow needs an minWidth of ~500 or buttons are masked without any possibility to click them : it probably won't be difficult to add a ">" menu when size is too small (even if I'm unsure how), enlarging "size" problem raising with some kind of "fit" placement when the window is bigger (actually for now buttons stay in place on the left and won't move)
upper/lower case are ignored (read "will work well") by using the following MySQL where clause to handle the letter parameter passed"WHERE SUBSTRING(people.name FROM 1 FOR 1) = '".$_POST["letter"]."'"
the GridPanel will put the "lowercase starting" names (should not exist with names! but you could have the problem for something else) sorted but after the (also sorted) "uppercase starting" names until you add the " type: 'string' " to the "name" field of your data.Record
if one says "I would prefer in a tab style!" I would answer "I won't do it for you" or even "read more about the cls config option for the Ext.Button in the API and do some CSS"
See you!
And as my first message in here, I do thank ALL the team and EACH user contributing. It's a real pleasure to see what a wonderful work can be done within here. =D>
Now, here is my first kind of contribution. I came to the need of a "standard" GridPanel with quite usual "add, delete" buttons to manage a list of people. But I wasn't satisfied with the "paging" system because when I'm searching for somebody in the list (read "the grid"), I'm used to click on his name's first letter as in an address book. So I decided to put all the letters in the top toolbar where I thought it would be great! Here is what I did, first creating the "alphaTbar" items :
var alphaTbarItems = new Array();
for(var i = 65; i < 91; i++) { // JS char codes from (upper) A to Z
var myChar = String.fromCharCode(i); // get the letter from the char code
alphaTbarItems.push({ // add this vars to the array
text: myChar, // just the letter
id: 'alphaTbarItem' + myChar, // this button id will contain the letter
enableToggle: true, // only one will be pressed
toggleGroup: 'alphaTbarItems',
handler: function() { // when this button is pressed
if (this.pressed) { // if it is now in a "pressed" state (toggle is enabled)
myDataStore.load({ // reload the dataStore
params: { letter: this.text, } // passing the letter as parameter
});
} else myDataStore.load(); // if it is unpressed, reload the dataStore with full list
}
});
}
Then here is the GridPanel :
var myListGrid = new Ext.grid.GridPanel({
border: false,
store: myDataStore,
columns: [
{header: 'Name', width: 140, sortable: true, dataIndex: 'name'},
{header: 'Zip', width: 35, sortable: true, dataIndex: 'zip'},
{header: 'City', width: 90, sortable: true, dataIndex: 'city'},
{header: 'Phone', width: 50, sortable: true, dataIndex: 'phone'},
],
viewConfig: { forceFit: true, },
// only one toolbar can be passed inline
tbar: myActionButtonsTopToolbar, // this one has add/delete/refresh buttons
bbar: myInfoBottomToolbar,
});
Then, two things are needed : showing the GridPanel (mine is in a window) and loading the dataStore :
myWindow.show();
myDataStore.load();
myAlphaTbar = new Ext.Toolbar({
renderTo: myListGrid.tbar, // that one line did the job!!
items: myAlphaTbarItems, // use formerly created buttons
});
myListGrid.syncSize(); // don't do that and the toolbar may not appear!
I've modified it "live" for the forum, but that should work like that :
http://img252.imageshack.us/img252/492/notitlepl3.png
Some notes :
myWindow needs an minWidth of ~500 or buttons are masked without any possibility to click them : it probably won't be difficult to add a ">" menu when size is too small (even if I'm unsure how), enlarging "size" problem raising with some kind of "fit" placement when the window is bigger (actually for now buttons stay in place on the left and won't move)
upper/lower case are ignored (read "will work well") by using the following MySQL where clause to handle the letter parameter passed"WHERE SUBSTRING(people.name FROM 1 FOR 1) = '".$_POST["letter"]."'"
the GridPanel will put the "lowercase starting" names (should not exist with names! but you could have the problem for something else) sorted but after the (also sorted) "uppercase starting" names until you add the " type: 'string' " to the "name" field of your data.Record
if one says "I would prefer in a tab style!" I would answer "I won't do it for you" or even "read more about the cls config option for the Ext.Button in the API and do some CSS"
See you!