@vtaits/qwik-filterlist v2.0.0
@vtaits/qwik-filterlist
Qwik wrapper above @vtaits/filterlist.
Installation
npm install @vtaits/filterlist @vtaits/qwik-filterlist --saveor
yarn add @vtaits/filterlist @vtaits/qwik-filterlistSimple examples
import { $, component$ } from "@builder.io/qwik";
import { useFilterlist } from "@vtaits/qwik-filterlist";
const List = component(() => {
const [listState, filterlist] = useFilterlist({
loadItems$: $(async () => {
const response = await fetch('/cars');
const cars = await response.json();
return {
items: cars,
total: cars.length,
};
}),
});
const {
items,
loading,
total,
} = listState.value;
return (
<div>
<table>
<thead>
<tr>
<th>id</th>
<th>brand</th>
<th>owner</th>
<th>color</th>
</tr>
</thead>
<tbody>
{
items.map(({
id,
brand,
owner,
color,
}) => (
<tr key={id}>
<td>{id}</td>
<td>{brand}</td>
<td>{owner}</td>
<td>{color}</td>
</tr>
))
}
</tbody>
</table>
{
typeof total === 'number' && (
<h4>
Total: {total}
</h4>
)
}
{
loading && (
<h3>Loading...</h3>
)
}
</div>
);
});Api
import { useFilterlist } from "@vtaits/qwik-filterlist";
// ...
const [listState, filterlist] = useFilterlist({
...options,
loadItems$,
parseFiltersAndSort$,
filtersAndSortData,
shouldRecount,
isRecountAsync,
onChangeLoadParams$,
canInit,
});listState and filterlist are null during async init or when canInit is true
Params
options - options of @vtaits/filterlist
parseFiltersAndSort$ - QRL function, receives
filtersAndSortDataas first argument, should return params for callfiltersAndSortDatamethod of @vtaits/filterlistfiltersAndSortData - see above
shouldRecount - function, called on every update of component. Receives new
filtersAndSortDataas first argument and oldfiltersAndSortDataas second. If returns true,parseFiltersAndSortwill called. By default checks equality with===operatorisRecountAsync - boolean, is
parseFiltersAndSortasync, false by defaultonChangeLoadParams$ - QRL function, callback of
changeLoadParamsevent of @vtaits/filterlistcanInit - boolean, filterlist will not be initialized until
canInitistrue