How to order 2 row groups in a specific order

How to order 2 row groups in a specific order

Abood_AAbood_A Posts: 2Questions: 1Answers: 0
edited May 23 in Free community support

**
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 need the opposite. Hope you can help.
**

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;
                    }
                     
                });
          }

**
I hope this helps too. As you can see down here, i specified that when the user_name is "Inactive", this user will be placed in the "Inactive User's" group, otherwise the user will be placed in the "Active User's" group.
**

{
"data": {
        "current_page": 1,
        "data": [
            {
                "id": 9,
                "user_id": 3,
                "project_id": 15,
                "created_at": "2024-05-17T08:46:25.000000Z",
                "updated_at": "2024-05-17T08:46:25.000000Z",
                "user_name": "Abood",
                "email": "aboodnashar@gmail.com",
                "user": {
                    "id": 3,
                    "name": "Abood",
                    "email": "aboodnashar@gmail.com"
                }
            },
            {
                "id": 18,
                "user_id": 1,
                "project_id": 15,
                "created_at": "2024-05-20T07:26:25.000000Z",
                "updated_at": "2024-05-20T07:26:25.000000Z",
                "user_name": "Inactive",
                "email": "nasharabood@gmail.com",
                "user": {
                    "id": 1,
                    "name": "Inactive",
                    "email": "nasharabood@gmail.com"
                }
            }
        ]
  }
}

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This data is identical to this thread - are you the same user using different accounts?

    Colin

  • Abood_AAbood_A Posts: 2Questions: 1Answers: 0

    @colin Yes the same user, I am still having problems with the question.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    I've added a reply in your other thread.

    Allan

Sign In or Register to comment.