Hi, I am trying to do a custom sort using the useI...
# gooddata-ui
y
Hi, I am trying to do a custom sort using the useInsightDataView() hooks. How can I get a "sort localIdentifier" (ex. ce1d36d564a5474a8e31d4e246ef9e8c) of a insight column from Md? I can find "sort localIdentifier" in result n2oMap by useInsightDataView() Do you have any "sort localIdentifier" getter in gooddata/sdk-model or "sort localIdentifier" from Md in gooddata/catalog-export ?
Copy code
// const { result } = useInsightDataView({...})
// {
//    ...
//    "n2oMap": {
//      "a_demo_for_gooddata_test_2.ad_name": "ce1d36d564a5474a8e31d4e246ef9e8c",
//      "m_zz_dummy_cpc_group_by_ad_name": "af4b8fecc67145caaeac124fbb9da9ce"
//    }
// }

const { error: originalError, status, result } = useInsightDataView({
    insight: {
        identifier: Insights[insightId],
    },
    sorts: [
        // Expected
        // I want to get the localIdentifier of a insight column from catalog.ts
        // ex. getLocalItentifier(insitghtId, Md.AdName) -> 'ce1d36d564a5474a8e31d4e246ef9e8c'
        // ex. getLocalItentifier(insitghtId, Md.ZzDummyCPC) -> 'af4b8fecc67145caaeac124fbb9da9ce'
        // ex. or Md.ZzDummyCPC.sortIdentifier -> 'af4b8fecc67145caaeac124fbb9da9ce'
        // for
        // newAttributeSort(getLocalItentifier(insitghtId, Md.AdName), 'asc'),
        // newMeasureSort(getLocalItentifier(insitghtId, Md.ZzDummyCPC), 'asc'),

        // Actual
        // attribute Working. I want the localIdentifier of a insight column
        // newAttributeSort('ce1d36d564a5474a8e31d4e246ef9e8c', 'asc'), // n2oMap value
        // meature Working. same as above
        // newMeasureSort('af4b8fecc67145caaeac124fbb9da9ce', 'asc'), // n2oMap value

        // Not working. Error(Invariant Violation: dangling localId reference. Target: a_demo_for_gooddata_test.ad_name)
        // newAttributeSort(Md.AdName, 'asc'), // a_demo_for_gooddata_test_2.ad_name
        // Not working. Error(Invariant Violation: dangling localId reference. Target: m_zz_dummy_cpc)
        // newMeasureSort(ZzDummyCPC.measure., 'asc'), //
    ]
})
Table Ad name, CPC
m
Hello @Yoshimori Otsuka, did you try to get it from the execution definition? You can provide sorts also as a function, which accepts the execution definition to be executed as an input, and returns the sort items
(def: IExecutionDefinition) => ISortItem[])
y
Thank you for answering my question. I read your answer and I search the function you tell me. I will answer your question and I have other questions. I want your reply.
did you try to get it from the execution definition?
Yes, unfortunately I get the measureOrId from he result (the execution definition) which is returned by useInsightDataView(). However, I want the measureOrId for newMeasureSort() from some getter(insightId, Md) or Md.
You can provide sorts also as a function
Is this insightSorts from gooddata/sdk-model? I can't find it well. Perhaps your function doesn't satisfies my problem (how to get measureOrId from some getter(insightId, Md) or Md?) because I want use useInsightDataView() and set sorts using
newMeasureSort
from measureOrId in my application. ref. https://gdui-examples.herokuapp.com/execute/use-insight-data-view-hook
m
@Yoshimori Otsuka Hello again, I don't think we currently have any getter for this. As you can have multiple same measures/attributes in the execution definition, you can't determine them just by their identifier/uri. But I think it should be possible to write your own getter, and get the local id from the execution definition, like this:
Copy code
const { error: originalError, status, result } = useInsightDataView({
    insight: {
        identifier: Insights[insightId],
    },
    sorts: (executionDefinition) => {
        // get measure local id from the execution definition
        const measureLocalId = yourOwnGetterToGetMeasureLocalIdFromExecutionDefinition(executionDefinition); 

        return [newMeasureSort(measureLocalId, 'asc')]; // return sorts
    }
})
y
@Matyáš Kandl Thank you for your answer. Your answer can help me to (come in / get) the something roadmap that solve this issues. 😃 I've thought about sorts function from your answer. And for next step (from your answer ), I need below maybe. I understand to implement this. • to use (executionDefinition) => SortItem[] instead SortItem[] • to implement yourOwnGetterToGetMeasureLocalIdFromExecutionDefinition Thanks ! I'll close this thread