Our pure JavaScript Scheduler component


Post by jfmartin »

Sorry if my question is an easy one.

I have a grid with a gantt that is working fine, but we want to make a modification to sort the data.

The sort need to be a combination of 2 properties of the data.

For testing purpose, i add a new column name "orderByfield" to see the result of the 2 properties together. I also add fill the property "sortable" with a function to sort the data.

 columns: 
    [ 
    { 
      text: ' ', 
      field: "orderByfield", 
      width: 20, 
      hidden: false, 
      renderer(things: { record: { originalData: { displayIndex: number, factoryId: number, name: string } } }) { 
        return things.record.originalData.factoryId + " " + things.record.originalData.displayIndex; 
      },       

  sortable: (rec1: any, rec2: any) => (rec1.factoryId + " " + rec1.displayIndex) < (rec2.factoryId + " " + rec2.displayIndex) ? -1 : 1, 
}, 

As I read in the doc and forum, it's working when we click of the header.

But i didnt succeed to do the same thing when the form open for the first time.

i tried different thing without success.
Thanks for your help.


Post by mats »

Instead of doing the work twice (once in renderer and once in sortable), just add a custom getter method to your Task model and use that as your field.

get orderByfield() {
    return this.factoryId + " " + this.displayIndex; 
}

and then you can delete sortable since you don't need it anymore.


Post Reply