PDA

View Full Version : Provide the default column model with a visible property


rodiniz
10-11-2006, 07:17 AM
How about put in the default column model a property named visible (with default true)
that allows the programmer to put a hidden column in the grid?
I know I can do that with code ..but some columns are meant to be hidden forever.

Animal
10-11-2006, 07:21 AM
There's a "hidden" property which defaults to false...

jack.slocum
10-11-2006, 07:43 AM
Just wondering, why have a column that's hidden forever?

rodiniz
10-11-2006, 08:32 AM
An id column thats not the id of the datamodel.
You want to get the value of that column ...but there is no reason to show the user.

jack.slocum
10-11-2006, 08:35 AM
It can be present in the data model without being present in the grid. That's something that was added in the .32.2 release. Check out the blog post and the dataIndex property. You can map columns to any column in the data model and leave some out (but still access them in the data model like normal).

Animal
10-11-2006, 09:23 AM
Talking of the dataIndex property.

When column moving is implemented, how will this work?

I assume that an event will be fired to the column model which says "column x has moved to column y".

These will be actual ColumnModel indexes?

jack.slocum
10-11-2006, 09:35 AM
No the column model index will be the same so it doesn't break anything. It will just be moved internally. Restoring that state after the grid loads will probably be an additional property visibleIndex or something. If visibleIndex is not provided then obviously the default index would be used. This should turn out to be flexible. Sound good to you?

Animal
10-11-2006, 09:57 AM
Maybe I'm not understanding.

The dataIndex property of each column in the ColumnModel specifies the index in each row to pass to DataModel.getValueAt().

So to get the data from a row, you might use:


for (var column = 0; column < this.columnModel. getColumnCount(); column++)
{
var value = this.dataModel.getValueAt(curRow, this.columnModel.getDataIndex(column));
}


So, dragging the column headers just will change the dataIndex property in the ColumnModel yes? The DataModel will not need to change.

So a move can just fire an event to/call a method on the ColumnModel with actual, column indexes for "from" and "to".

By default, the ColumnModel just has to shuffle the data indexes around.

I don't see the need for another property.

jack.slocum
10-11-2006, 10:15 AM
No, that's what's so cool about the layout code. When the user reorders the columns, there's no need to rerender. All I will do is move the column (physically move it) to the new location. All underlying code stays the same. Your column config stays the same. The only difference is the column will have a new x coordinate. For tracking what order that coord should be in, I will introduce the visibleIndex property. This way if you have code that performs some other operation based on column index (like maybe updating a header) that code won't need to keep track of the correct column index based on the user order. It can access them like usual.

Animal
10-11-2006, 10:24 AM
Oh, OK, so visibleIndex specifies the order of display of the data.

So by default, if unspecified, visibleIndex will be taken as identical to dataIndex. Column move operations will change the visible index, so when I save state, I have to supply the visibleIndex properties in the ColumnModel.

jack.slocum
10-11-2006, 10:36 AM
Kinda. Visible index will match the columnIndex. Maybe this is just too confusing.

ColumnIndex - > DataIndex - map a grid column to a data model "column"
VisibleIndex - > ColumnIndex - Map a grid column to it's display order

Or even better:

var cm = new ....DefaultColumnModel([
{ <-- columnIndex is always 0
header: "First Name",
dataIndex: 7, <-- always points to dataIndex 7
visibleIndex:1 <-- even though it's column 0, we want it to be displayed in position 1
}, { <-- columnIndex is always 1
header: 'Last Name',
dataIndex: 8, <-- always points to dataIndex 8
visibleIndex: 0 <-- even though it's column 1, we want it to be displayed in position 0
}
]);

cm.setColumnHeader(1, "Surname"); // still works, even though its displayed in column 0


visibleIndex is only there to restore an individual user's preference, so you don't want to have to change all your code to map to the user's preference, you just want to be able to set the display order.

The default visible index will be the columnIndex, dataIndex is unrelated.

Animal
10-11-2006, 10:54 AM
OK, visibleIndex is what I have to save in my Preferences object, and send out in my array of ListColumn objects. Got it, thanks.