PDA

View Full Version : Populating Array Grid with one column hidden



15 Feb 2007, 7:02 AM
Hi,

I am using Array Grid and populating grid form an array. But I wanted to know

1. Can I Populate grid with columns id, name,salary using Array Grid so that in the grid id column remains hidden and is represents the row id of grid
with array



var myData = [
[1,'John',5000],
[2,'Petric',8000]
]


just like what we do in dase of ajax xml grid using


var schema = {
tagName: 'Item',
id: 'ASIN',
fields: ['Author', 'Title', 'Manufacturer', 'ProductGroup']
};


Can I use arrays in this case to populate grid.

bone
15 Feb 2007, 8:52 AM
http://www.yui-ext.com/deploy/yui-ext/docs/output/YAHOO.ext.grid.DefaultColumnModel.html#setHidden





myDataModel = new YAHOO.ext.grid.DefaultDataModel([
[1,'john',5009],
[2,'peter',8000]]);

var cols = [
{header: "Id"},
{header: "Name"},
{header: "Salary"}];

myColModel = new YAHOO.ext.grid.DefaultColumnModel(cols);
myColModel.setHidden(0);
myGrid = new YAHOO.ext.grid.Grid('div-of-my-grid', myDataModel, myColModel);


At least I think this is what you're looking for

15 Feb 2007, 8:37 PM
Hi,

Thanks for replying.

I tried to use


myColModel.setHidden(0);


to hide my column but it did not worked but when I tried



myColModel.setHidden(0,true);

It works fine where as in documentation we do not have any such method
docs say


public function setHidden(Number colIndex)
Sets if a column is hidden.


Thanks

tryanDLS
15 Feb 2007, 9:01 PM
You can specify hidden in your columnModel


{header:id, hidden:true}

bone
15 Feb 2007, 11:43 PM
actually im using setHidden(0,true) myself, and it was used in my original reply in this thread. but i went back a couple of hours later and changed it to setHidden(0) because thats what it says in the docs (i didnt want to spread faulty code blabla)

this is from DefaultColumnModel.js:


/**
* Sets if a column is hidden.
* @param {Number} colIndex The column index
*/
setHidden : function(colIndex, hidden){
this.config[colIndex].hidden = hidden;
this.totalWidth = null;
this.fireHiddenChange(colIndex, hidden);
},


once again we prove that code > docs

tryanDLS
16 Feb 2007, 8:15 AM
I would say that you were right to begin with. The docs are wrong. The correct usage is
setHidden(0, true) or setHidden(0, false) to hide or show the column. However, note that calling this method fires the hiddenchange event. You may or may not have this event hooked, but if you do, it may not be correct to fire it when you are initially building the columnModel.

If you're making a column hidden initially, e.g. when you're creating the CM, the way to do it is in the config with


{header:id, hidden:true}

This way you don't fire an event that may have unintended consequences.