DataTables grouping with ordering

DataTables grouping with ordering

Abdelrahman_AlnasharAbdelrahman_Alnashar Posts: 1Questions: 1Answers: 0

I have a DataTable for grouping users who are active and inactive, I want to be able to order the inactive users first, then the active ones. The code below results in grouping the active users first, I want the opposite.

columnDefs: [
            { visible: true, targets: groupColumn }
          ],
          order: [[groupColumn, 'asc']],
        displayLength: 10,
        lengthMenu: [10, 15, 20, 25, 30],
        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(user_status, i) {
                  var group = user_status === "Inactive" ? "Inactive Users" : "Active Users";
                  
                  if (last !== group) {
                        $(rows)
                            .eq(i)
                            .before(
                              '<tr class="group" ' + groupStyle + '><td colspan="4">' +
                                group +
                                '</td></tr>'
                            );

                        last = group;
                    }
                    
                });
          }
Sign In or Register to comment.