2

I am trying to perform multiple grouping in my data tables, I can manage to group by one column thanks to this example.

https://datatables.net/examples/advanced_init/row_grouping.html

Does anybody know about any plugin that works with angular and angularDatables (https://l-lin.github.io/angular-datatables/#/welcome) to group the data by more than one column?

Thanks in advance.

asked Jan 27, 2017 at 0:57

2 Answers 2

2

In case of anybody was having the same problem, the only thing I did to the code provided in https://datatables.net/examples/advanced_init/row_grouping.html, was to use the same code for every column I wanted to group.

api.column(0 { page: 'current' })
.data()
 .each(function(group, i) {
 if (last !== group) {
 $(rows)
 .eq(i)
 .before(
 '<tr class="group"><td colspan="5">' + group + '</td></tr>'
 );
 last = group;
 }
 });
api.column(1 { page: 'current' })
.data()
 .each(function(group, i) {
 if (last !== group) {
 $(rows)
 .eq(i)
 .before(
 '<tr class="group"><td colspan="5">' + group + '</td></tr>'
 );
 last = group;
 }
 });
answered Jan 27, 2017 at 1:28
Sign up to request clarification or add additional context in comments.

Comments

2

Based on @Martha's answer, it works also for angular 5 in this way:

 var groupColumn = 1;
 this.dtOptions = {
 // pagingType: 'full_numbers',
 pageLength: 10,
 responsive: true,
 language: { search: "" },
 order:[1,'desc'],
 columnDefs: [
 { type: 'date-uk', targets: 1} // specifying date format
 ],
 drawCallback: function ( settings ) {
 var api = this.api();
 var rows = api.rows( {page:'current'} ).nodes();
 var last=null; 
 api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
 if ( last !== group ) {
 $(rows).eq( i ).before(
 '<tr style="background-color:#dedede" class="group"><th colspan="5">'+group+'</th></tr>'
 ); 
 last = group;
 }
 });
 }
 };
answered Aug 29, 2018 at 9:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.