getCell with multiple subgrids

Questions related to our Sencha Touch based grid component
Post Reply
User avatar
LarssaAndin
Posts: 18
Joined: Fri Mar 01, 2013 12:28 pm

getCell with multiple subgrids

Post 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 :(.

User avatar
nickolay
Core Developer
Core Developer
Posts: 3466
Joined: Mon May 16, 2011 10:48 am

Re: getCell with multiple subgrids

Post 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?
We offer training in both Ext JS and our products, read more here.
Read the API documentation

User avatar
LarssaAndin
Posts: 18
Joined: Fri Mar 01, 2013 12:28 pm

Re: getCell with multiple subgrids

Post 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.

User avatar
nickolay
Core Developer
Core Developer
Posts: 3466
Joined: Mon May 16, 2011 10:48 am

Re: getCell with multiple subgrids

Post 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!
We offer training in both Ext JS and our products, read more here.
Read the API documentation

User avatar
LarssaAndin
Posts: 18
Joined: Fri Mar 01, 2013 12:28 pm

Re: getCell with multiple subgrids

Post 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?

User avatar
nickolay
Core Developer
Core Developer
Posts: 3466
Joined: Mon May 16, 2011 10:48 am

Re: getCell with multiple subgrids

Post 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.
We offer training in both Ext JS and our products, read more here.
Read the API documentation

User avatar
LarssaAndin
Posts: 18
Joined: Fri Mar 01, 2013 12:28 pm

Re: getCell with multiple subgrids

Post 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.

User avatar
nickolay
Core Developer
Core Developer
Posts: 3466
Joined: Mon May 16, 2011 10:48 am

Re: getCell with multiple subgrids

Post by nickolay »

Ok, all mentioned methods are added now. Please check them in the nightlies.
We offer training in both Ext JS and our products, read more here.
Read the API documentation

User avatar
LarssaAndin
Posts: 18
Joined: Fri Mar 01, 2013 12:28 pm

Re: getCell with multiple subgrids

Post 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.

User avatar
nickolay
Core Developer
Core Developer
Posts: 3466
Joined: Mon May 16, 2011 10:48 am

Re: getCell with multiple subgrids

Post by nickolay »

Ok, fixed in the sources, thanks for the report. "getLocalIndex" now returns same value as "getIndex" if there are no sub grids.
We offer training in both Ext JS and our products, read more here.
Read the API documentation

Post Reply