Workflow and ServiceDesk Community

 View Only

Workflow Angular Grid - How to Set Initial Groupings 

Sep 19, 2018 09:43 AM

I was asked by a colleague to help find a way to provide grouping functionality within the grid component in Workflow.  Using the Angular options, this worked for him; however, there was no way to have the grid load with initial groupings (as far as we could tell).  After a bit of trial, error, and effort, I found a way to preload the groupings in the Angular grid.

Give your grid a specific Control ID on the Functionality tab.

  • Example: TestGrid

Supply the component with the usual required parameters.

  • Grid Mode
  • Data Type
  • Is Array
  • Grid Data
  • Columns

On the Response tab, select Allow Grouping if you want the user to be able to interact with the grouping feature.

On the General tab, select Use Angular JS.

At the project's top level options, select Use Angular Js Capability.

Now we're ready to include some javascript to make the grouping happen. In order to properly code the grouping, we'll need to know the name of the column as it is used in the data itself. I'll assume (though I have not thoroughly researched) that the rendered HTML column matches the Object's Property Column as configured in the Workflow grid component; so start with that and go from there. 

Include whichever following script is appropriate into your form's Behavior tab, as an added onload action. Double-click any empty space on your form, or right-click and select Edit Form in any blank space inside or outside your form in the Form Builder canvas.

setTimeout(function() {$('#TestGrid').data("kendo-grid").dataSource.group({field: "OSName"});}, 100); 

The setTimeout delay is used because the kendo Angular component takes just a tiny moment to render, meaning that we need to delay our script long enough to allow the grid to complete. Otherwise, the script we run will not find the target dataSource. Depending on the data displayed in the grid, the delay may need adjustment to suit. The 100 value in the script above is the delay, in milliseconds.

The colleague for whom I worked on this solution needed multiple initial groupings.  The code was then adjusted to force an array of groupings, as such:

setTimeout(function() {$('#TestGrid').data("kendo-grid").dataSource.group([{field: "OSName"},{field: "OSVersion"}]);}, 100); 

Note the square brackets added in to indicate an array.

If pre-sorting on those groupings is desired, add a few directionals in:

setTimeout(function() {$('#TestGrid').data("kendo-grid").dataSource.group([{field: "OSName", dir: "asc"},{field: "OSVersion", dir: "desc"}]);}, 100); 

asc and desc being 0->9, A->Z and 9->0, Z->A, respectively.

That should do it!  Hopefully that'll help someone else out in the future!

Statistics
0 Favorited
2 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Sep 20, 2018 09:33 AM

That's actually why I amended the article with my comment; the colleague for whom I created the initial fix was attempting to use a Subdialog with the Angular features enabled, and it would not open.  

The problem seems to be ultimately with the Angular feature being enabled for the Subdialog component. The secondary problem here is that when you attempt to clear that checkbox, it will not remain cleared. It seems as though if Angular is enabled at a project-level, it's enabled for everything.

Sep 20, 2018 12:22 AM

Hi Andrew,

 

Creat article! 

Have you ever had issues using the Angular components with a sub dialog? Everytime I use Angular the sub dialog would automatically close after ±10 seconds.

 

Cheers,

Rufus

Sep 19, 2018 05:34 PM

Because there are some inherent (and from what I can tell, unavoidable) issues with Angular functionality in Workflow presently, here's how to do it without the Angular option enabled:

var
    grid = $('#TestGrid').data('fb-grid')
   ,col1 = grid.columns[4]
   ,col2 = grid.columns[5]
;

if(!(grid.groups.indexOf(col1) > -1)) {
  grid.addGroup(col1,0);
};
if(!(grid.groups.indexOf(col2) > -1)) {
  grid.addGroup(col2,1);
};

In the code above, columns[4] and columns[5] are simply the index position of the columns I want to group by, captured as variables (col1 and col2, respectively).

In the second part, addGroup(col1),0) indicates that I'm setting col1 (the first column I want to group by) as the first grouping, being index position 0 in the grouping array. addGroup(col2,1) places columns[5] in the second (index position 1) position in the grouping array.  This achieves the same result as the original Angular solution, without the buggy angular feature included.

It also seems that the delay (setTimeout) function is not needed when angular is not enabled, but if you experience issues, then toss it back in.

EDIT:: Adjusted and cleaned up the code to account for page refresh.  Previous code was allowing duplicated groupings.

Related Entries and Links

No Related Resource entered.