Basic itemrenderer widget
July 22, 2011 by Acatl Pachecohttps://github.com/acatl/jquery.itemrenderer
This widget is to be used as a definition of the basic options itemrenderer widgets will have.
Definition ir.itemrenderer.js widget:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Examples
Examples of the use of this widget are as follow:
Example 1
The most basic way to use this widget would be just passing a simple array to the options’s dataProvider.
| 1 2 3 4 5 6 |
|
Example 2
You may also use objects as items of your dataProvider, the default object’s field that the itemrenderer will take as a label is “label”.
Example:
{
label: "lorem"
}
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Example 3: labelField
If you wish to specify a different field you may use the option labelField es shown below:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Example 4.1: labelFunction
You may use labelFunction to apply process your label output.
Top option labelFunction is a function with the following signature:
labelFunction(data, options);
- data
- the current item from the iteration object of the dataProvider
- options
- a reference to the widget’s options
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Example 4.2: labelFunction, using the options argument
| 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 |
|
Example 5: rendererFunction
If you wish to go even further on the processing of your output of each iteration you may use the option rendererFunction which gives you more control on how the DOM element being iterated will be treated.
The function’s signature goes as follows:
rendererFunction(container, listData)
- container
- reference to the container’s jQuery object of the current iteration
- listData
- Object with the definition options of the current iteration
listData definition:
This object usually contains the following properties:
- owner
- A reference to the widget’s instance (this)
- label
- the current label already processed by any definitions passed to the options
- data
- the raw data item of the current iteration
- options
- the options of the itemrenderer
- index
- the index of item’s current position in the dataProvider’s collection
| 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 |
|
Example 6: itemRenderer
Let’s take the rendering of the items to the next level, itemrenderer is a string that holds the name of a widget’s id you wish to attach to each item on the iteration.
when the widget is attached to the element one object is passed:
{ listData: listData }
Where listData as mention previously will contain information necessary to render the item.
| 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
Tags: jquery Widgets
Categories: Widget
Permalink
-
http://itemrenderer.com/?p=93 jQuery Grid Widget « itemrenderer
