Skip to content
This repository was archived by the owner on Apr 2, 2019. It is now read-only.

Move _direction state variable out of HeaderCell and into Column#256

Merged
wyuenho merged 1 commit intocloudflarearchive:masterfrom
egeste:column-model-state
Aug 4, 2013
Merged

Move _direction state variable out of HeaderCell and into Column#256
wyuenho merged 1 commit intocloudflarearchive:masterfrom
egeste:column-model-state

Conversation

@egeste
Copy link
Copy Markdown
Contributor

@egeste egeste commented Jun 26, 2013

I believe this proposal will create more flexibility in implementing custom cells. I do not assume this commit is complete, but rather intend to start a dialog about the topic.

I believe this proposal will create more flexibility in
implementing custom cells. I do not assume this commit is complete,
but rather intend to start a dialog about the topic.
@wyuenho
Copy link
Copy Markdown
Contributor

wyuenho commented Jun 26, 2013

This will certainly make it easier to put a css class to the header cell depending on "change:direction". This will open the door for configuring an initial sorting for a grid upon initialization as well.

@egeste
Copy link
Copy Markdown
Contributor Author

egeste commented Jun 26, 2013

What additional changes, if any, would you like to see in this commit to accept it?

@wyuenho
Copy link
Copy Markdown
Contributor

wyuenho commented Jun 26, 2013

Tests :)

@kriswill
Copy link
Copy Markdown

the sort logic should also be in the column, such as the makeComparator() and the sort function itself. Then the click handler can simply call this.column.sort(this.direction()). This is what I had monkey patched in my application to enable "saving" the column sort order for the grid.

I also added a sortType to the column definition which allowed me to dispatch a special comparator based on date, integer and the default locale case string sorting. I would use this from my version of the makeComparator factory to produce each type of comparator based on the setting.

@wyuenho
Copy link
Copy Markdown
Contributor

wyuenho commented Jun 27, 2013

@kriswill Or you could just trigger backgrid:sort on the collection.

This PR looks fine, just needs some tests.

@kriswill
Copy link
Copy Markdown

well the reason I did it like this, is because I actually save the column settings. HeaderCell isn't a model, it's a DOM element with a click event. It just doesn't work for me to have it owning the comparator factory, or the sort state.

@kriswill
Copy link
Copy Markdown

Oh, In my application I have a list of "Reports", each one has a selection of fields that map to columns, and it can be saved by name, edited, have it's columns rearranged, sorted and exported as a CSV.

@wyuenho
Copy link
Copy Markdown
Contributor

wyuenho commented Jun 27, 2013

I actually save the column settings

This is what this PR will do.

@wyuenho
Copy link
Copy Markdown
Contributor

wyuenho commented Jun 27, 2013

I guess the only thing that's missing is sorting automatically on initialization based on the column direction value. Can you do something about this @egeste ?

@kriswill
Copy link
Copy Markdown

bingo! That's exactly it.

@wyuenho
Copy link
Copy Markdown
Contributor

wyuenho commented Jun 27, 2013

Automatically sorting on grid init can be done very simply inside HeaderCell's initialize function as well.

@kriswill
Copy link
Copy Markdown

The problem I have with that is that it requires you to render the grid first. Or that the Grid has to exist. It seems to me that the Columns SHOULD be able to be used independently of any relationship to the Grid or it's sub-views. For instance, I provide a menu of available columns which allows the user to toggle a column's renderable bit.

@wyuenho
Copy link
Copy Markdown
Contributor

wyuenho commented Jun 28, 2013

Columns can already be used independently. It can be independent in the sense that you can do whatever you want to it what you can do with a Backbone.Collection. Moving all the sorting logic to Column defeats this purpose. What's the use of sorting the rows collection headlessly without being able to display them?

I'm not even sure I understand your concern. Are you trying to say you want to be able to programmatically sort a grid from an independent control that connects to the Columns collection only? If that's the case this PR can also be amended so that a HeaderCell can listen to its Column's direction attribute and sort the rows in the event listener.

@kriswill
Copy link
Copy Markdown

In my application the steps are like this:

  1. initialize the columns, use stored settings
  2. make the comparator with the column(s) that are sorted (user defined)
  3. initialize the collection with comparator (so the items are added in correct sort order)
  4. initialize the Grid, render, show "Loading Sign"
  5. fetch the collection, the Grid reacts to the collection
  6. take down loading sign, user interacts, makes column setting changes, etc

I could just as easily have separated the logic for the acquiring the comparator for the collection. However, the minimalist in me would prefer there was only one factory defined for it. To me the HeaderCell is just UI, it shouldn't be involved with owning the factory for a collection comparator. The Column seems like the natural place for this.

Do what you want, but I think when you get to the sorting multiple columns feature, you'll find it easier to implement from the Columns object.

@wyuenho wyuenho mentioned this pull request Jul 11, 2013
5 tasks
@ghost ghost assigned wyuenho Aug 3, 2013
wyuenho added a commit that referenced this pull request Aug 4, 2013
Move _direction state variable out of HeaderCell and into Column
@wyuenho wyuenho merged commit 5a161dc into cloudflarearchive:master Aug 4, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants