DeeboData JS Grid Angular Grid
Contact Us Demo Pricing

DeeboData Javascript Datagrid Custom Column Sort

JavaScript Data Grid

  • Custom Sort

  • Pass a custom sort by column

    Pass an object with 2 top level properties called asc and desc that are objects themselves. Then each property for the asc and desc objects should be a column name and of type function. Each column name property should implement the standard ECMAScript sort callback function for however you want that column to be sorted for ascending (asc) and descending (desc) sorts.
    function setCustomSortObj() {
    const field = "category";
    let obj = {
    asc: {
    category: (a, b) => {
    if(!a[field] && a[field] !== 0)
    return 1
    if(!b[field] && b[field] !== 0)
    return -1
    if(a[field] > b[field])
    return 1
    if((a[field] === b[field]) || (JSON.stringify(a[field]) === JSON.stringify(b[field])))
    return 0
    return -1
    }
    },
    desc: {
    category: (a, b) => {
    if(!a[field] && a[field] !== 0)
    return 1
    if(!b[field] && b[field] !== 0)
    return -1
    if(a[field] > b[field])
    return -1
    if((a[field] === b[field]) || (JSON.stringify(a[field]) === JSON.stringify(b[field])))
    return 0
    return 1
    }
    },
    }
    deebo.methods.setColumnSort(obj);
    }

    setCustomSortObj()//call the custom sort setter function defined above
    deebo.methods.initDeeboData("YOUR_LICENSE_KEY")