Dynamic data and pagination/sort/search #1453
-
I'm looking at using grid.js together with sqlite.js. I see that I can use the dynamic data import, but then I would have to query the entire table and keep all rows in memory. Is there a way to use lazy loading analogous to server-side pagination/sort/search? |
Beta Was this translation helpful? Give feedback.
Answered by
AdrianVollmer
Aug 10, 2024
Replies: 1 comment
-
I realized I can use the custom HTTP client and pass options via the url parameter: const grid = new gridjs.Grid({
columns: columns,
server: {
data: (opts) => queryDb(opts),
},
pagination: {
limit: 20,
server: {
data: (opts) => queryDb(opts),
url: (prev, page, limit) => {
const result = prev || {};
result.page = page;
result.limit = limit;
return result;
},
},
},
search: {
server: {
url: (prev, keyword) => {
const result = prev || {};
result.keyword = keyword;
return result;
},
},
},
sort: {
multiColumn: true,
server: {
url: (prev, columns) => {
if (!columns.length) return prev;
const result = prev || {};
const order = columns.map((c) => {
return {
order: columns[c.index].label,
direction: c.direction === 1 ? "ASC" : "DESC",
};
});
result.order = order;
return result;
},
},
},
resizable: true,
style: { td: { "font-family": "monospace" } },
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AdrianVollmer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I realized I can use the custom HTTP client and pass options via the url parameter: