Button to automate "group first by ..."

My users frequently use the “group first by …” option in the sort menu:

image

It’s a critical analysis to look at both angles, and I was wondering if it’s something that I can automate for them. Anyone have any ideas?

I have noticed that when the group order is changed, the order of columns does change in table1.control.rowHeaderColumns so I tried to swap columns 0 and 1 in code, but it didn’t seem to work.

1 Like

So far, I’ve figured out that when I use the sort menu to do it, it makes a call to moveelementbefore in the API. I found that in the API documentation, but don’t know how to translate it into use for my javascript button.

https://www.dundas.com/support/api-docs/net/#html/M_Dundas_BI_Entities_MetricSets_MetricSet_MoveElementBefore.htm?Highlight=moveelementbefore

i got video incoming shortly for you.

1 Like

Hi @ken - Hope this helps you.

3 Likes

Thanks, @jeff, but that link just takes me to the videos page. Which one did you want me to see?

Odd - it takes me to the page where I hosted the video. Here is the direct video link.

2 Likes

Whoa! @jeff, I was not expecting a fully customized video just for my question! Thank you so much!

I’m going to try to implement that in a few minutes. It also helped give me a few other ideas along the way for similar user functionality. Love it!

Side note: Steven Lam showed me how to use the Network function in the console to see what the Dundas API is doing when I change the grouping order in that sort menu. However, I couldn’t really connect what’s there to javascript code. Do you have any videos on taking the API docs info and making it work in a button?

2 Likes

No problem, Ken. I saw your post, and it was a question I also wanted to know how to do as well. I thought it would be a very good way to show some scripting once I figured it out. Hope it helps.

As for the network watch, I’m not sure how easily that is going to translate to JavaScript docs. I guess it would give you clues, but I couldn’t comment on a specific methodology.

1 Like

OK! Finally got back to working on this. I couldn’t get my button working because it depended on which state I was starting in, and it wasn’t consistent. So, I built a toggle button instead:

var overridesLength = this.parentView.control.overrides.metricSetBindingOverrides.length;

if (overridesLength == 0) //if the overrides don't yet exist, create them with a default state
{
  var overrides = JSON.parse("[...AllThatStuffFromTheVideo...]");
  this.parentView.control.overrides.metricSetBindingOverrides = [overrides];
  table1.loadData();
}
else //if they DO exist, get the current column order and swap the first 2 (what I want for my case)
{
  var colOrder = this.parentView.control.overrides.metricSetBindingOverrides[0].requestOverrides.sortPriorityOverrides;

  var newFirst = colOrder[1];
  colOrder[1] = colOrder[0];
  colOrder[0] = newFirst;

  this.parentView.control.overrides.metricSetBindingOverrides[0].requestOverrides.sortPriorityOverrides = colOrder;
  table1.loadData();
}

Works like a charm. @jeff thank you for the great video to get me 90% of the way there!

2 Likes

Just back from a mini-vacation. Glad to see that you have it sorted @ken! cheers.

1 Like