Created
June 12, 2015 11:35
-
-
Save tsyber1an/fedf051228b9a5c5fae8 to your computer and use it in GitHub Desktop.
Example remote data with filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var React = require('react') | |
var DataGrid = require('react-datagrid') | |
var columns = [ | |
{ name: 'id', title: '#', width: 150 }, | |
{ name: 'firstName'}, | |
{ name: 'lastName' }, | |
{ name: 'city', width: 200 }, | |
{ name: 'country', width: 200 }, | |
{ name: 'email'} | |
] | |
module.exports = React.createClass({ | |
render: function(){ | |
return <DataGrid | |
dataSource='http://5.101.99.47:8090/1000' | |
idProperty='id' | |
columns={columns} | |
onFilter={this.handleFilter} | |
liveFilter={true} | |
style={{height: 500}} | |
/> | |
}, | |
handleFilter: function(column, value, allFilterValues){ | |
//reset data to original data-array | |
data = data1000 | |
//go over all filters and apply them | |
Object.keys(allFilterValues).forEach(function(name){ | |
var columnFilter = (allFilterValues[name] + '').toUpperCase() | |
if (columnFilter == ''){ | |
return | |
} | |
data = data.filter(function(item){ | |
if ((item[name] + '').toUpperCase().indexOf(columnFilter) === 0){ | |
return true | |
} | |
}) | |
}) | |
this.setState({}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment