-
Notifications
You must be signed in to change notification settings - Fork 324
[Feature request] Allow different types of cell in same column. #611
Comments
One solution could be to pass callback function in column schema which will be called before every cell being rendered. (function will be called with contex [this] as current column and argument as current model instance) And that function should return valid cell class to make new cell instance. column: [ {name: 'name', label:'Name', type:'text', editable: false, cell: 'string'},
{name: 'value', label:'Value', type: 'text', editable: true,
cellFunction: function(model){
if (isNaN(model.get(this.get('name')))) {
return "string"; // Backgrid.StringCell
} else {
return Backgrid.NumberCell;
}
}
},
{ name: 'database', label:'Database', type: 'text', editable: false},
.
. |
Is anybody working on this? |
Is it working? I have the next error: TypeError: column.get(...) is not a constructor. Thanks! |
Well I have raised pull request for this feature without test cases but it's not merged yet. Alternatively you can still make this working without waiting for pull request get merged. Approach 1 (Not recommended): I have setup another backgrid repo with working example. You can visit repo. Approach 2 (Recommended): Extend backgrid itself (Thanks to JavaScript's Prototype-Based Inheritance) and include this feature. You will need to add some code (I'll provide working code reference below). In pgdmin4 open source project we have used this feature many places. pgAdmin4 is a database management tool so based on datatype in left column we need to render appropriate cell (for eg. string, integer, number, checkbox, boolean cell) in right column and this where I realized backgrid to have such feature. How to implement. You'll only need code change from this file web/pgadmin/static/js/backgrid/backgrid.pgadmin.js from above commit. Examples: Also there are many other places where we have used this feature. schema.js |
Many Thanks!! I have got make this work, but only controlled models that come from the server. Any ideas? |
For new model this should be working. Make sure you are adding new models in collection properly (collection.add()). This will automatically trigger "add" event on collection and backgrid listens to this event, creates and inserts new row. While creating new row it get cell class from cell attribute of column schema or calls cellFunction (if provided) to get new cell class. Regarding controlling such behavior on the fly (model modification) there is no support in backgrid. We had such requirement in pgAdmin4. If user changes variable type in left column then corresponding cell in right column (in same row) should change. See below two screen-shots Switch cell (boolean cell) in value column You can find relevant code in this commit (search for var VariableRow which is custom row which handles changing of cell (cell type) on the fly on model change i.e variable name change) |
There should some mechanism to render different types of cell in same column.
The text was updated successfully, but these errors were encountered: