Plugins
Datatable
The datatable plugin hooks up a datasource to a table, and provides for sorting and various features.
Datatable from markup
# | First Name | Last Name | Language |
---|---|---|---|
1 | Mark | Otto | CSS |
2 | Jacob | Thornton | Javascript |
3 | Stu | Dent | HTML |
4 | Brosef | Stalin | HTML |
Usage
nwt.one('#mytable1').plug('Datatable');
JSON Datatable
Usage
nwt.one('#mytable2').plug('Datatable', {
columns: [{name:'bbq?', key: 'one'}, 'two', 'three'],
data: [
{one: 'bbq', two: 'ketchup', three: 'mustard'},
{one: 'dog', two: 'cat', three: 'raining'},
{one: 'Dave', two: 'Logan', three: 'Tony'}
]
})
// Click on a row to retreive the data that populated it
nwt.one('#mytable2').on('click', function(e){
alert('Row data: ' + JSON.stringify(e.target.getTableData()))
}, 'td')
IO Datatable
Usage
nwt.one('#mytable3').plug('Datatable', {
columns: ['one', 'two', 'three'],
data: nwt.io('/nwt/jekyll/jsondata.txt')
});
// By default we fetch via post, but it's easy to override
nwt.one('#mytable3').plug('Datatable', {
columns: ['one', 'two', 'three'],
data: nwt.io('/nwt/jekyll/jsondata.txt'),
fetch: function(io, sort, dir) {
io.get('sort=' + sort + '&dir=' + dir);
}
});