ItemsJS
ItemsJS - movies demo
HTML
<script src="https://cdn.rawgit.com/itemsapi/itemsjs/master/dist/itemsjs.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.min.css">
<script src="https://cdn.rawgit.com/itemsapi/itemsapi-example-data/master/jsfiddle/imdb.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.9.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.6/umd/react-dom.production.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
React
class ItemsJS extends React.Component {
constructor(props) {
super(props);
this.state = {
configuration: {
searchableFields: ['title', 'tags', 'actors'],
sortings: {
name_asc: {
field: 'name',
order: 'asc'
}
},
aggregations: {
tags: {
title: 'Tags',
size: 10
},
actors: {
title: 'Actors',
size: 10
},
genres: {
title: 'Genres',
size: 10
}
}
}
}
var newFilters = {};
Object.keys(this.state.configuration.aggregations).map(function (v) {
newFilters[v] = [];
})
// Copying this.state using the spread op (...this.state)
this.state = {
...this.state,
// the rows comes from external resources
// https://github.com/itemsapi/itemsapi-example-data/blob/master/jsfiddle/imdb.js
// In React line below is:
//itemsjs: require('itemsjs')(rows, this.state.configuration),
itemsjs: itemsjs(rows, this.state.configuration),
query: '',
filters: newFilters,
}
}
changeQuery(e) {
this.setState({
query: e.target.value
});
}
reset() {
var newFilters = {};
Object.keys(this.state.configuration.aggregations).map(function (v) {
newFilters[v] = [];
})
this.setState({
filters: newFilters,
query: '',
})
}
handleCheckbox = (filterName, filterValue) => event => {
const oldFilters = this.state.filters;
let newFilters = oldFilters
let check = event.target.checked;
if (check) {
newFilters[filterName].push(filterValue)
this.setState({
filters: newFilters
})
} else {
var index = newFilters[filterName].indexOf(filterValue);
if (index > -1) {
newFilters[filterName].splice(index, 1);
this.setState({
filters: newFilters
})
...