Hi, I am trying to do a custom sort using the useI...
# gooddata-ui
h
Hi, I am trying to do a custom sort using the useInsightDataView hook. The sample looks like it can be done, but I am getting the following error How can I get it to sort? Is there something wrong with the way the arguments are specified? https://gdui-examples.herokuapp.com/sorting
j
Hello. I am not entirely sure what the reasoning behind the error is, but is there a reason for why you are defining the measures this way? Using the md export script, your workspace’s metadata would be defined this way:
Copy code
export const Price = {
  /**
   * Fact Title: Price
   * Fact ID: PRICE
   * Fact Aggregation: sum
   */
  Sum: newMeasure(idRef("PRICE", "fact"), (m) => m.aggregation("sum"))
  /**
   * Fact Title: Price
   * Fact ID: PRICE
   * Fact Aggregation: avg
   */,
  Avg: newMeasure(idRef("PRICE", "fact"), (m) => m.aggregation("avg"))
  /**
   * Fact Title: Price
   * Fact ID: PRICE
   * Fact Aggregation: min
   */,
  Min: newMeasure(idRef("PRICE", "fact"), (m) => m.aggregation("min"))
  /**
   * Fact Title: Price
   * Fact ID: PRICE
   * Fact Aggregation: max
   */,
  Max: newMeasure(idRef("PRICE", "fact"), (m) => m.aggregation("max"))
  /**
   * Fact Title: Price
   * Fact ID: PRICE
   * Fact Aggregation: median
   */,
  Median: newMeasure(idRef("PRICE", "fact"), (m) => m.aggregation("median"))
  /**
   * Fact Title: Price
   * Fact ID: PRICE
   * Fact Aggregation: runsum
   */,
  Runsum: newMeasure(idRef("PRICE", "fact"), (m) => m.aggregation("runsum")),
};
From here, I could do, for example:
Copy code
import * as md from '../md/full'
import { newMeasureSort } from "@gooddata/sdk-model";
import { useInsightDataView } from "@gooddata/sdk-ui";



const Home: React.FC = () => {
    const { result, error, status } = useInsightDataView({ 
        insight: idRef(md.Insights.BigInsight),
        sorts: [newMeasureSort(md.Price.Max, 'desc')]
    }
Does your insight display correctly if you skip adding the sort?