Start a new topic

Kinvey Studio

Hi I have a parent form which lists 8 items (called Sections). When an item is selected, a subform opens, displaying a list of records which are categories and subcategories of the selected Section. The list is grouped by category. So my data model is Sections have Categories, and Categories have Subcategories. In the subform I have the selected entity collection and a collection of category data (which has the categories and related subcategories). I have attached the ts code for the subform. My question is - in the tns.ts file I have customised initData so that I sort by subcategory by creating a new categoriesOptions object that keeps the instance and the onChanges configuration to that which is set in the base component .ts file, and added sorting to the initialState object. However, the problem is that the subcategory data is not being sorted and I am thinking that this needs to be configured in the onChanges, which appears to override the initialState. It doesnot appear possible to set the sort order in the onChanges at this point in time. Thanks in advance for your assistance with this. Code for both files is attached. Regards Janine
1 Comment

Hello Janine,

Thank you for sharing your code and pointing out this issue.

Your scenario should work just fine when done through initialState. However, it appears that we have a bug that makes this impossible at the moment. We will work on resolving the issue and in the meantime, you can use onChanges instead. Here is a basic example on how this should look:

protected initData(config: { [key: string]: DataServiceConfig }) {
    const data = super.initData(config);

    const categoriesSort = [
            field: 'subcategory',
            dir: 'asc'
    data.dataServices.categories.onChanges.push(of(() => ({ sort: categoriesSort })));

    return data;

Let me know if the above helps you to resolve the issue.



Login or Signup to post a comment