KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

DataTable Row Gouping #2094

Closed Chris Sideris opened this topic on on May 19, 2021 - 2 comments

Chris Sideris commented on May 19, 2021

I am using DataGrid's DataTable and I would like to group some of the rows according to the different column values depending on each grouping. I am looking to mimic something like this https://datatables.net/examples/advanced_init/row_grouping.html

Is there a way to do that?

Chris Sideris commented on May 19, 2021

Hey, I have solved it with

"options"=>[
	"drawCallback"=>"function ( settings ) {
                    var api = this.api();
                    var rows = api.rows( {page:'current'} ).nodes();
                    var last=null;
                     
                    //0 here is the column value to group the rows by
                    api.column(0, {page:'current'} ).data().each( function ( group, i ) {
                        if ( last !== group ) {
                            $(rows).eq( i ).before(
                                '<tr class=\"group\"><td colspan=\"2\">'+group+'</td></tr>'
                            );
                            last = group;
                        }
                    } );
	                }"
]

Thanks

Sebastian Morales commented on May 20, 2021

Chris, it's brilliant of you to make DataTables' client script work with DataTables widget. Beside this approach, we also have a row group property to make it easier for developers:

DataTables row group documentation

DataTables row group example

Hope this be useful to you. Tks,

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

DataGrid