Exgrid has rebuild with reactive-lite, beside flexable binding methods and binding resue for excellence performance, it can do:
- paging
- sorting
- filter
- local/remote mode
- custom formatter/render
- data change reactive
- event delegation
with npm
npm install exgrid --save
Define a template like this:
<table>
<thead>
<tr>
<th class="sort" data-sort="name">name</th>
<th class="sort" data-sort="age">age</th>
<th>company</th>
<th class="sort" data-sort="number">money</th>
<th>active</th>
</tr>
</thead>
<tbody>
<tr>
<td class="left">{name}</td>
<td style="width:30px;">{age}</td>
<td class="left">{company}</td>
<td class="money">¥{money | currency 2}</td>
<td data-render="setActive" class="center"></td>
</tr>
</tbody>
The last tr
element in tbody
is used as the template for repeat rendering.
Init the grid, render it to html and set data:
var grid = new Grid(template, {
perpage: 10,
// filters for reactive-lite
filters: {
percentage: function (val) {
return (val*100).toFixed() + '%'
}
},
// bindings for reactive-lite
bindings: {
react: function (prop) {
this.bind('$stat', function (model, el) {
...
})
}
},
// delegate object for reactive-lite
delegate: {
setActive: function (model, el) {
...
}
}
})
// use local mode
grid.local()
// render element
placeholder.appendChild(pager.el)
grid.setData(data)
sort
emit with params when remote sort needed (includingsortField
sortDirection
)filter
emit with params when remote filter needed (includingfilterField
filterValud
)page
emit with params when remote paging needed (includingcurpage
,perpage
)change
emit after table row add or removedremove
emit just before this component removed
##API
el
table element or template string as root nodeoption
optional option for list-renderoption.perpage
max page count perpage, works with pager (need Object.definePropety support)option.delegate
delegate object for reactiveoption.bindings
bindings object for reactiveoption.filters
filters object for reactiveoption.model
model class used for generate modeloption.empty
String or Element rendered in parentNode when internal data list is emptyoption.limit
the limit number for render whensetData()
(equal to perpage if not set)
Exgrid inherits all methods from list-render, the extra methods are shown below
Delegate event type
to selector
with handler
,
handler is called with event and a reactive model
Make list works on local model, which means sort, filter and paging only happens locally
Sort the data by field, direction or method, when it's remote mode(default mode), emit event only
Filter the data by field, val or function, when it's remote mode(default mode), emit event only
Select page n
, when it's remote mode(default mode), emit event only
Set total data count for paging, can not used for local mode
Unbind all events and remove the created elements
The MIT License (MIT)
Copyright (c) 2015 Qiming Zhao chemzqm@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.