tzezar / datagrid

Datagrid made in svelte. Easy to use. Easy to customize.
https://tzezars-datagrid.vercel.app
MIT License
105 stars 2 forks source link

Filtering runs twice #1

Closed tzezar closed 2 weeks ago

tzezar commented 1 month ago

Current behaviour:

Internal logic runs twice

Expected behaviour:

Internal logic runs once

Description:

In order to apply logic to the initial data as well as later update that data when filtering changes, using $effect we listen for changes to datagrid.state.filters. For a reason unknown to me, svelte detects the change in data on the first render even data stays the same.

$effect(() => {
if (datagrid.mode === 'client') {
    datagrid.internal.filteredData = filterData([...datagrid.data], datagrid.state.filters);
}
});

This results in whole chain of unnecessary logic applied to data, like pagination and sorting. It is very visible with huge datasets because sorting is expensive operation in some cases.

Potential solution:

tzezar commented 2 weeks ago

I will rewrite the datagrid logic in my spare time to expose functions like sortData(), filterData(), paginateData() on the datagrid instance which will be triggered by events like changing the filter etc. this will remove $effect() and hopefully, fix the duplicate logic application.

There is also the question of whether it would then be prudent to abandon the separation of these data states (filtered, sorted, paginated - data) in favor of one such as postProcessedData

tzezar commented 2 weeks ago

paginatedData, filteredData, sortedData no longer exist. Instead, use datagrid.state.processedData.