Page 1 of 1

getCell with multiple subgrids

Posted: Mon Mar 11, 2013 11:28 am
by LarssaAndin
I'm working on creating a selection model for my grid and it's going pretty well. I have one major problem though. The interaction between celltap that gives row and cell/col index that is relative to the current subgrid doesn't work very well together with getCell on the panel component that works with the global cell indexes. The effect with having one locked column is that I get a column index that is one step wrong when using getCell. The reason I need the cell is that I need to do addCls and removeCls on the selected/deselected cells.

The Sencha grid component works the same with the coordinates at the click event and that is how my backed data structure expects it to work so that part is fine, even though it might not be perfect if you start from scratch, can't really say what is best in the long run though. What I would like to see is a way to do getCell on the subgrid level (Simple). Either as a method in the simple class or as an extra parameter to getCell on Panel that figures out what to do by itself. I could maybe also use a getColumnCount() on the simple grid so I could do the calculations myself (this is how I work around it at the moment as I happen to know that I will always have only one locked column, but that is not very nice code :(.

Re: getCell with multiple subgrids

Posted: Mon Mar 11, 2013 11:49 am
by nickolay
Hm.. Right, good point. I think the API should be flexible in this regard. We need:

1) "getCell" method on the sub grid class, it will expect "local" cell index.
2) "getSubGridCell" method on the main panel, receiving subgrid instance/index and cell offset inside of it
3) cell tap event (and all other events) should also contain "global" cell offset, so the signature of the event will be: (panel, record, rowIndex, localCellIndex, globalCellIndex, simpleGrid, event)

What do you think?

Re: getCell with multiple subgrids

Posted: Mon Mar 11, 2013 12:25 pm
by LarssaAndin
Thank you for the quick response!

It looks lovely! All those changes would be perfect :D

I'm now also looking at header events to be able to do select column using a header tap. I haven't started experimenting yet so I'm not totally sure what can be done right now, but it's not obvious how to get access to the cells of a column based on a header tap.

I seem to be able to get all the relevant columns (leafs in my case) but translating a column instance to the correct column index seems very difficult.

It's not just a matter of adding column index to the header events as there are multiple levels of headers and I want to be able to select all leaf columns by clicking at the top header. I guess the best would be a way to ask a column for its local index in the subgrid. Getting the global index should also be available for symmetry if not too complicated.

Re: getCell with multiple subgrids

Posted: Mon Mar 11, 2013 12:44 pm
by nickolay
Columns forms a tree. Each column has an unique internal id and IIRC that id is added as css class to the column's cell. You can find the child of some column in "children" property, or if you only need leafs - with "getLeafs()" method.

Please post feature requests for API you need - we'll add it soon!

Re: getCell with multiple subgrids

Posted: Mon Mar 11, 2013 1:04 pm
by LarssaAndin
Ok, I have now written some code. I understand that the columns are in a tree (visually the headers are in a tree). What I do need is to get the real column index (called cellindex in the cell events).

API sugestion for the Column class:
getLocalColumnIndex() -> number = the columns index relative to the subgrid it's located in
getColumnIndex() -> number = the columns index relative to the whole ubergrid

Does this sound reasonable?

Re: getCell with multiple subgrids

Posted: Mon Mar 11, 2013 1:16 pm
by nickolay
Yes, it does. If you want to hack something yourself right now, see "getFirstLeafIndex" method for an inspiration on "getColumnIndex". As about the "getLocalColumnIndex" - check `groupChildrenByType` where we create additional tree nodes for each sub-grid. Otherwise I'll try to add these two methods by the end of this week.

Re: getCell with multiple subgrids

Posted: Mon Mar 11, 2013 2:04 pm
by LarssaAndin
Excellent, I'm looking forward to the next release! :D

Ok, I'll see if I'll play around with it. Right now I can cheat by using data I get from the server, but I'd prefer to get the real indexes to make the solution more adaptable.

Re: getCell with multiple subgrids

Posted: Tue Apr 09, 2013 12:15 pm
by nickolay
Ok, all mentioned methods are added now. Please check them in the nightlies.

Re: getCell with multiple subgrids

Posted: Tue Apr 09, 2013 5:09 pm
by LarssaAndin
Now I've worked with it a bit and the changes seems to be working.
I found one small issue where getLocalIndex() fails if there no subgrids. It's not really wrong as there aren't really a relevant "local" context to get index for but some guard code to handle this might be relevant.

Re: getCell with multiple subgrids

Posted: Tue Apr 23, 2013 12:41 pm
by nickolay
Ok, fixed in the sources, thanks for the report. "getLocalIndex" now returns same value as "getIndex" if there are no sub grids.