[#384,slickgrid][s]: slickgrid sets editor type automatically from field type.

* multiview demo now has editing turned on
* [license][xs]: update to 2011-2014.
This commit is contained in:
Rufus Pollock 2014-01-12 22:44:20 +00:00
parent a4475a05d2
commit 45fa438803
3 changed files with 37 additions and 3 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2011 Max Ogden & Contributors
Copyright (c) 2011-2014 Max Ogden, Rufus Pollock and Contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -73,7 +73,18 @@ var createExplorer = function(dataset, state) {
id: 'grid',
label: 'Grid',
view: new recline.View.SlickGrid({
model: dataset
model: dataset,
state: {
gridOptions: {
editable: true,
enabledAddRow: true,
enableCellNavigation: true
},
columnsEditor: [
{ column: 'date', editor: Slick.Editors.Date },
{ column: 'title', editor: Slick.Editors.Text }
]
}
})
},
{
@ -81,6 +92,7 @@ var createExplorer = function(dataset, state) {
label: 'Graph',
view: new recline.View.Graph({
model: dataset
})
},
{

View File

@ -23,7 +23,11 @@ this.recline.View = this.recline.View || {};
// model: dataset,
// el: $el,
// state: {
// gridOptions: {editable: true},
// gridOptions: {
// editable: true,
// enableAddRows: true
// ...
// },
// columnsEditor: [
// {column: 'date', editor: Slick.Editors.Date },
// {column: 'title', editor: Slick.Editors.Text}
@ -113,6 +117,24 @@ my.SlickGrid = Backbone.View.extend({
var editInfo = _.find(self.state.get('columnsEditor'),function(c){return c.column === field.id;});
if (editInfo){
column.editor = editInfo.editor;
} else {
// guess editor type
var typeToEditorMap = {
'string': Slick.Editors.LongText,
'integer': Slick.Editors.IntegerEditor,
'number': Slick.Editors.Text,
// TODO: need a way to ensure we format date in the right way
// Plus what if dates are in distant past or future ... (?)
// 'date': Slick.Editors.DateEditor,
'date': Slick.Editors.Text,
'boolean': Slick.Editors.YesNoSelectEditor
// TODO: (?) percent ...
};
if (field.type in typeToEditorMap) {
column.editor = typeToEditorMap[field.type]
} else {
column.editor = Slick.Editors.LongText;
}
}
columns.push(column);
});