Issue in search when used with row grouping

Issue in search when used with row grouping

rohanyerolkarrohanyerolkar Posts: 5Questions: 1Answers: 1
edited July 17 in Free community support

Hi,

I have jquery datatable with two level row grouping. If i search anything in the table, it searches the data correctly but removes all grouping or merges all searched data into one group. Also, it works fine for one level grouping.

I have tried most of things i found on the internet but none of them were useful.

does anyone know anything about this?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 41,043Questions: 1Answers: 5,074 Site admin

    How are you doing your row grouping? The RowGroup extension doesn't support two levels of grouping I'm afraid.

    Allan

  • rohanyerolkarrohanyerolkar Posts: 5Questions: 1Answers: 1

    I have used drawcallback function for this -

    drawCallback: function (settings) {

                var api = this.api();
                var rows = api.rows().nodes();
                var last = null;
                var counter = 0;
                api.column(9, {  }).data().each(function (group, i) {//page: 'current'
                    if (last !== group) {
                        counter = counter + 1;
                        $(rows).eq(i).before(
    
                            '<tr class="groupPeriod" ><td colspan="8">' 
    
                            '<b><label style="padding-left:30px">' + group.toString().toUpperCase() + '</label></b></td></tr>'
    

    );

                        last = group;
                    }
                });
                api.column(8, {  }).data().each(function (group, i) {//page: 'current'
                    if (last !== group) {
    
                        $(rows).eq(i).before(
    
                            '<tr class="group" style="background-color:gainsboro"><td colspan="8">' +
    
                            '<b><label style="padding-left:30px">' + group.toString().toUpperCase() + '</label></b>' 
    

    );

                        last = group;
                    }
                });
    
  • allanallan Posts: 41,043Questions: 1Answers: 5,074 Site admin

    You'd need to update your grouping every time the draw event is triggered.

    Allan

  • rohanyerolkarrohanyerolkar Posts: 5Questions: 1Answers: 1
    edited July 18

    Could you please give any example? I am trying this but not able to solve. My drawcallback function is getting called from search event but result is the same.

  • allanallan Posts: 41,043Questions: 1Answers: 5,074 Site admin

    Hmm - actually you are using drawCallback already - I didn't see that since it wasn't in the code highlighting. That should be all that is needed.

    Really I'd need a test case to understand why it isn't working.

    Allan

  • rohanyerolkarrohanyerolkar Posts: 5Questions: 1Answers: 1

    I have the similar problem mentioned in this post : http://jsfiddle.net/j4n87xvy/3/

    Search results are not displaying grouping.

  • allanallan Posts: 41,043Questions: 1Answers: 5,074 Site admin

    The example isn't running because of Javascript errors. However, DataTables won't automatically detect any grouping from the data-tt-id attributes (etc).

    I don't see anything actually doing any grouping there.

    Allan

  • rohanyerolkarrohanyerolkar Posts: 5Questions: 1Answers: 1
    Answer ✓

    I found the solution.

    I had missed "{ page: 'current' }" in below line of code in DrawCallBack function

    var rows = api.rows({ page: 'current' }).nodes();

Sign In or Register to comment.