I am developing an app where users can perform CRUD operations on multiple data models (aka. DB tables). I am using Dojo and I am quite happy with the dojox.grid
module. But users also need to add records, so there has to be an Add Dialog for each table.
Is there a way/module that generates a Dojo grid and an Add Dialog given only the data structure of the model? Sort of like the structure
parameter of dojox.grid
, so that both the grid and the add Dialog have the same data types, default values, contraints etc.
Of course I could write a custom widget that would just do that but I am looking for something existing here.
The answer is, no there is no such module. You'd need to build a derived dialog.
Lets see whats needed;
Assuming there is one 'Add contents' button defined pr-grid and that this button 'knows' the ID of the said grid, its onClick function should fire up a form in dialog.
While there are dijit.form Widgets there's also a range of predefined
cellTypes
, residing underdojox/grid/cells/_base.js
. Lets make a map where type and widget is 1to1:In our addContents function we will make use of the 'editable' functionality in the dojox.grid.DataGrid. When we know there's a such - there is certainly also a function pr-cell that generates the DOM. This is the formatEditing function which is present in any cellType.
Only thing thats needed is to construct the contents which should be shown in the dialog - following uses the above mentioned functionality and provides dijit suitable markup for presentation in a dijit.Dialog.
The contents is easy style-able and should also supply a submit/cancel button but im certain you get the idea. Running sample
Let me know how it runs (havent tested combobox / datetime types)