DATA ENGINE PREVIEW
Simple data engine, to provide sort and filter. It can work with custom dataset.
DATA-ENGINE
Create new data-engine
const engine = new DataEngine();
const engine2 = new DataEngine(data);
const engine3 = new DataEngine(data, 'primary key');
const engine4 = new DataEngine(data, 'primary key', sortFunction, fetchFunction);
Set data
engine.setData(data);
Updating filters
const filteredData = engine.update(filter, filter2, filter3);
Updating sort
const sorted = engine.sortBy('new name');
Note: when you call update sort with same key it will automatically reverse array;
removing filters
const filteredData = engine.removerFilter('name of filter', filter);
Clearing filters
const filteredData = engine.clearFilters();
Clearing sort
const filteredData = engine.clearSort();
Resorting
const filteredData = engine.sortData();
Getting data
const filteredData = engine.getData();
Note: Data engine should have same functions from sort and filter that are mentioned below.
FILTER-VALUE
Creating new filter value
const filter = new FilterValue('name');
const filter2 = new FilterValue('name', 'Criteria');
const filter3 = new FilterValue('name', 'Criteria', 'type');
Updating filter value
filter.Name = 'New Name';
filter.Value = /New value/i;
filter.Type = 'regex';
Removing type
filter.removeType();
Getting values
const name = filter.Name;
const value = filter.Value;
Possible value types
boolean
function
array
regexp
date
string
number
range
**
** Note: range can only contains string
, number
or date
Static type values
number
string
regexp
boolean
When static type is set, it will try to parse value as this type!
WARNING
Note: Filter value using prototype changes which are dangerous.
Note: When you using regexp please use FilterValue.regexEscape('Some regular expression')
FILTER
Creating new filter
const filterEngine = new Filter(data);
Updating data
filterEngine.setData(newData);
Adding and updating filters
const filteredData = filterEngine.update(filter, filter2, filter3 );
Removing filters
const filteredData = filterEngine.removeFilter(filter, 'name' );
Clearing filters
const filteredData = filterEngine.clearFilters();
Getting data
const filteredData = filterEngine.getFilteredData();
SORT
Creating new Sort
const sort = new Sort(data);
const sort2 = new Sort(data, 'Primary key');
const sort3 = new Sort(data, 'Primary key', CustomSortFunction);
Updating data
const data = sort.updateData(newData);
const data2 = sort.updateData(newData, true);
Updating criteria
sort.setSortFunction(CustomFunction);
sort.setPrimaryKey('new key');
Removing criteria
sort.removePrimaryKey();
sort.setDefaultSort();
Sorting data
const data = sort.sortBy('name');
Getting data
const data = sort.getData();
Resorting data
const data = sort.justSort();
WHAT NEXT
Add promise like for big data!
Test all usecases
Set filter-value manually