Query-it
Pure Javascript data processing tool. Including filter, sort, search, paginate.
Install
Node.js or webpack
$ npm install query-it -S
CDN
Usage examples
Simple
; const query = ; const SOURCE_DATA = name: "Donald Clark" age: 21 name: "Paul Lee" age: 22 name: "Ruth Rodriguez" age: 19 ;query;query; console; // [// { name: "Paul Lee", age: 22 },// { name: "Donald Clark", age: 21 },// { name: "Ruth Rodriguez", age: 19 }// ];
Or CDN
const QueryIt = windowQueryItdefault;const query =
Hooks
Apply a callback function and debounce waiting time (default 0).
const query = { console;} 300;
Props
Name | Description |
---|---|
items | Displayed data. Readonly |
total | The amount of data before paginating. Default 0. Readonly |
pageCount | Total pages count. Default 1. Readonly |
currentPage | Current page number. Default1. Readonly. |
pageSize | Maximum number per page. Default -1. Readonly. if less than 0, it will get all of data. |
Methods
load
Loading source data and init states.
search
Searching by text and fields.
query; // field name or email including "pa"
You can also provide your custom search strategy.
query;
filter
Filtering by query object.
// name equal to "Paul Lee" or "Donald Clark"// and sex equal to "female" // and age greater than 18query;
Also apply a filter function likes Array.filter
sort
Same with lodash/orderby. Or provide a custom sort function likes Array.sort
setCurrentPage
Set current page number.
query
If the current page number is greater than page count. The current page number will be set to page count.
setPageSize
Set the page size.
query
if less than 0, it means get all of data.
Usage with Javascript framework
React
There is an awesome way to use with react hooks.
;;
And just use it normally.
Vue
By Vue.observable
or vue-composition-api
. And I think the vue-composition-api
seems to be the most pupular way to write vue project in future.
;;
It should work well but unfortunately doesn't. Because the reactive
rewrite the original reactivity. So we need to declare some new reactive state.
;;
It is not an elegant solution but worked. 🤕