CodeCoupler UI DataSource Mixin "Extended Fields"
A DataSource Mixin providing an extended model definition.
Common Rules for Field Definitions
Absolute minimum is "fieldName: {}". The id field must not be defined. If defined it should be not editable "idFieldName: {editable:false}".
Basic Field Definitions for DataSource
- type: string
The available options are "string", "number", "boolean", "date" and "object".
-
defaultValue: value The default value for "string" is "", for "number" is 0, and for "date" is new Date() (today). Even not documented the default value for "boolean" seems to be false. The parameter can also be set to a function that returns the dynamic default values.
-
from: string Specifies the field of the original record whose value is used to populate the Model field. When CRUD operations (specifically adding new items) are enabled, the original field name should be defined with a defaultValue as well. But this is not mandatory if it is just a string with a defaultValue of "".
-
parse: function(value) Specifies the function which will parse the field value. If not set default parsers will be used. If you need more then the value of the field to build a result, you could use "formatter".
Some Helper
-
constant: value The given value will always be set for this field (it will be converted in a parse function) and the default value will be set to this value if no default property is otherwise defined.
-
optionalFrom: string Like "from", but it preprocess the responce and set the value of the field to "null" if not defined. If you use just "from" kendo would throw an error if this property do not exist. The refernce in sub-objects is supported (string can be "a.b.field" for example). If you are using schema.data as a function you must know that these fields will be created after executing your function!
-
calculated: function(value,dataItem,args) || [ function, args ] The function receives (in contrast to "parse") additionally the whole item received from the server. You can calculate on that base and return any value the field should get. The function will receive the value of the field if this exists. Otherwise "value" will be "undefined". You can set an array with first argument the function and as second argument any value that will be passed to the function as third parameter. Do not use this with "from" or "optionalFrom" as the value will be set from these fields. If you are using schema.data as a function you must know that your function will be called first.
Visual Definition
Extended Field Definitions used by grids or other widgets will be included in the property "visual". The property can be set to "false". In this case the field should be invisible. Otherwise it should be an object which should contain definitions used by other widgets. Here are the most important fields used by ccGrid:
-
editor: SlickEditor JavaScript Object which will be created providing an interface like a Slick-Editor. Default if not set depends on field type:
-
string: cc.Editors.Text
- number: cc.Editors.Integer
- boolean: cc.Editors.Checkbox
- date: cc.Editors.Date
-
object: cc.Editors.Text
-
formatter: function(row, cell, value, columnDef, dataContext) Basically it is the same as "parse", but "parse" will get only the value of one field. "formatter" will get much more informations where you can parse on.
-
title: string Title presented in a column header for example. If not set the name of the field will be used.
-
columnGroups: string String to combine columns in one group. A second header row will be shown.
-
width: integer Width of column in pixel.
Best Practice / Extend this base class
CHAPTER NOT READY
Normally you would set your base in the default options - as shown above - before instatiating any DataSource. Then you can write for each model an own class by extending this base class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|