How to done row grouping at server side?

How to done row grouping at server side?

yogesh123yogesh123 Posts: 5Questions: 4Answers: 0

Hi,
I have done the row grouping on client side and it works fine on client side ..But when it comes to server side the row grouping is not showing in proper way.it makes the separate group of individual parent row and each child row.I am stuck with this problem.
plz give me suggestion on this with example..

This question has an accepted answers - jump to answer

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39
    Answer ✓

    Following the row-grouping example worked fine for me with server-side data. So if you are having an issue, we would probably need to see your code.

  • yogesh123yogesh123 Posts: 5Questions: 4Answers: 0

    I try the server side grouping with your code.But it still not giving me satisfy result.Grouping is not done in proper way.datable group at each row.Here is my jquerry code and I am grouping the row on groupName field of json.
    "drawCallback": function ( settings ) {
    var api = this.api();
    var rows = api.rows( {page:'current'} ).nodes();
    var last=null;

                                api.column(3, {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;
                                    }
                                } );
                            }
    

    } );
    $('#example tbody').on( 'click', 'tr.group', function () {
    var currentOrder = table.order()[0];
    if ( currentOrder[0] === 3 && currentOrder[1] === 'asc' ) {
    table.order( [ 3, 'desc' ] ).draw();
    }
    else {
    table.order( [ 3, 'asc' ] ).draw();
    }

                        } );
    

    and I am grouping the row on groupName field of json

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39

    Also sort by the same column that you group by or you will see a ton of group header rows. So if you are grouping by column 3, add in order: [[ 3, 'asc' ]] into your datatable code, where you have your serverSide: true. I also disable sorting with bSort:false because while I like the row grouping, I really don't care for it when it has been sorted.

This discussion has been closed.