[Table] How should look like sort provider function?
See original GitHub issueHello,
My function looks like:
sortProvider(ctx) {
this.isBusy = true;
const promise = fetch(`http://localhost:3000/photos?_sort=${ctx.sortBy}&_order=${ctx.sortDesc ? 'asc' : 'desc'}`);
return promise
.then((data) => {
this.totalPhotos = parseInt(data.headers.get('X-Total-Count'), 10);
return data.json();
})
.then((data) => {
this.isBusy = false;
return data;
});
},
The function works perfect I get sorted data, but table does not reflect to data change.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Sort data in a table - Microsoft Support
Sort the table. Select a cell within the data. Select Home > Sort & Filter. Sort&Filter. Or, select Data > Sort. DATA-Sort&Filter. Select...
Read more >Video: Sort data in a range or table - Microsoft Support
Select a range of data, such as A1:L5 (multiple rows and columns), or C1:C80 (a single column). The range can include titles (headers)...
Read more >Creating a React sortable table - LogRocket Blog
In this case, we will use the sort() function. However, depending on the item's data type, we can sort elements using different methods....
Read more >Implementing Custom Sorting in Columns in JavaScript
This tutorial will describe how to give your users the ability to sort table columns using the MatTable's built-in sorting mechanism. Demo ...
Read more >Creating Sortable Tables With React - Smashing Magazine
Making your tables sortable in React might sound like a daunting task, ... We need to do this because the Array.prototype.sort function ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
sort-changed
is just a notification event that the sorting has changed/cleared. It doesn’t receive the sort data or callback or promise.sort-changed
is only needed when you are returning an array (or setting an array) via the :items
prop.The provider function assigned to
:items
will be called when the sorting changes (as long asno-provider-sorting
is not set.The
ctx
object provided to the:items
provider function includes thesortBy
andsortDesc
.So do this:
Example:
App definition:
In this example, anytime you click on a pagination page, or sort by clicking a header, then
myProvider
will be called with the contextctx
object set with the appropriate values.