Hi,
I'm fairly new to Retool and wanna seek some advice. I connected by spreadsheet data source to Retool so my colleagues could check it. But whenever we sort the data by date, it's not sorted properly. Please see attached screenshot.
Hi,
I'm fairly new to Retool and wanna seek some advice. I connected by spreadsheet data source to Retool so my colleagues could check it. But whenever we sort the data by date, it's not sorted properly. Please see attached screenshot.
Hey @Fry ,
Welcome to Retool Community.
I understand your problem , you have to use javascript to sort date or any data in ascending or descending manner, table default sort function works well with Retool DB data, but if you saw any error or issue then Javascript is the best option.
By getting sort value from state of table and change data source to javascript function
If you want more help then feel free to ask.
Hi,
Thanks for your response.
I see, is there any tutorials on how I can change data source to javascript function? Also, you mentioned that the default sort function works well in Retool, so is the issue from the data source?
But yeah, any help you can provide is really appreciated, and will be happy to test it out. Thanks!
I will give you an example of javascript code and give an image to show where to change data source of table.
// Sample query data array
let queryData = [query2.data];
// Default sort by signup_date in descending order
queryData.sort((a, b) => new Date(b.signup_date) - new Date(a.signup_date));
// Function to apply sorting based on sortArray
function applySorting(data, sortArray) {
sortArray.forEach(sort => {
const { columnId, direction } = sort;
data.sort((a, b) => {
const valA = a[columnId];
const valB = b[columnId];
if (direction === "asc") {
return valA > valB ? 1 : valA < valB ? -1 : 0;
} else {
return valA < valB ? 1 : valA > valB ? -1 : 0;
}
});
});
}
// Example usage with dynamic sortArray
const sortArray = table1.sortArray;
applySorting(queryData, sortArray);
console.log(queryData);
return queryData[0];
I'm using retool db, but I'm running into the same issue. Do I have to use JS? It seems weird the table component can't do that. The DB sort works fine, so I can always do a custom handler.
db Asc
db desc
Yes, you will need to use Javascript here. I'm happy to help here if you're running into issues with your transformer!
you have to use javascript to sort date or any data in ascending or descending manner, table default sort function works well with Retool DB data, but if you saw any error or issue then Javascript is the best option.