Search code examples
javascriptnode.jsnpmdashboardmaterial-table

Is there a custom sorting function in material-table to sort file sizes?


I'm using material-table (mbrn/material-table) to develop a dashboard and I have column contains memory values with Megabyte (MB) and Gigabyte (GB). Normal sort option does not work as expected because of the different file sizes. Is there a custom sorting function in material-table to sort file sizes (MB & GB) ?

https://github.com/mbrn/material-table.git

above github repo I used to develop the dashboard.


Solution

  • No but you could write a custom logic to create your own filter in just a few seconds.

    // your logic
    const sortBySize() = (row, value) => {
         console.log('row', row, 'value', value);
    } 
    
    const columns = [
        { title: "File name", field: "fileName" },
        { title: "size", field: "size", customSort: sortBySize() }
    ];
    

    Useful link: https://material-table.com/#/docs/features/sorting (Custom Sorting Algorithm Example)