Control order in which columns are displayed

Hi all. I have a dataset with columns A, B & C. I want to show them in a spreasheet, using a specific order of columns, e.g. [B, C, A]. However, the data manager seems to order the columns into [A, B, C].


If I manually specify the rows, I can give an index for each field, and hence determine the order. How can I achieve the same effect with a data manager?


Thanks!

Jannes


2 Replies

JK Jannes Klaas January 4, 2022 06:24 PM UTC

Perhaps to clarify, the reason why I cannot rely on the order of the dictionary is that some of the column names are years, and hence get sorted as integers.



TS Thaneegairaj Sankar Syncfusion Team January 9, 2022 03:18 AM UTC

Hi Jannes,


We can able control the order in which columns were displayed, using the CustomAdaptor” concept. Using this we can override the default “ProcessResponse” method of the Adaptor and customize the data. Please refer to the below code example and sample link for more information.


class CustomAdaptor extends ODataAdaptor {

  public processResponse(): Object {

    let i: number = 0;

    //calling base class processResponse function

    let original: any = super.processResponse.apply(this, arguments).result;

    //Here you can override the response before assign to your component

    const sortOrder = { CustomerID: 1, EmployeeID: 2, OrderID: 3 };

    const res = original.map((o) =>

      Object.assign(

        {},

        ...Object.keys(o)

          .sort((a, b) => sortOrder[a] - sortOrder[b])

          .map((x) => {

            return { [x]: o[x] };

          })

      )

    );

    return { result: res};

  }

}


Documentation: https://ej2.syncfusion.com/documentation/data/querying/#projection-using-code-classlanguage-textselectcode


Sample: https://stackblitz.com/edit/ajcxqn?file=index.ts


Could you please check the above sample and get back to us whether it fulfill your requirement or need further assistance on this.


Regards,

Thaneegairaj S


Loader.
Up arrow icon