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

Add ability to extend Grid with default columns. #445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alettieri
Copy link

Add the ability to extend Backgrid.Grid with base columns. Might be particularly useful in scenarios where Grids will always have a number of columns to start with, keeping things a bit more 'dry'.

@wyuenho
Copy link
Contributor

wyuenho commented Feb 18, 2014

The idea is great, but the problem is once I've supplied some columns, they completely replace the defaults. They don't get merged. How to merge properly isn't obvious either. Experiment with that more and let me know? This might help with default column options too, so you don't have to keep saying editable:false for every column and just say editable:false 1 level up and that's sets the default for all the columns.

@alettieri
Copy link
Author

Thanks for your prompt reply!

Yeah, I agree. That was actually my first approach, but then I thought it should behave similar to an override, rather than extend. I will work that in and re-submit a pull request to get your input.

I actually extended the Column prototype to achieve the editable:false global setting. I think it would be nice not to have to do it the way I did in my current code:

//
// Define Custom Global defaults
//
_.extend( Backgrid.Column.prototype.defaults, {
    //
    // We want all columns to sort toggling
    //
    sortType: 'toggle',
    //
    // Nothing should be editable, unless we specify so.
    //
    editable: false
});

@gabriellupu
Copy link

@wyuenho basically you want to end up with something like this :

new Backgrid.Grid({
  defaultColumnOptions: {
    cell: "string"
  },
  ...
});

and all the columns will extend the options provided with defaultColumnOptions ?

@alettieri
Copy link
Author

Pretty much it, yup.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants