troubleshooting Question

Datatable sort column based on span attribute value

Avatar of Afif JABADO
Afif JABADO asked on
JavaScriptjQuery
8 Comments1 Solution96 ViewsLast Modified:
I have a column on my data table where i use specific function to create label

<td class="status sorting_1" ><span class="new badge blue" data-badge-caption="In progress"></span></td>

i want to sort base on  data-badge-caption="In progress"
i have three value In progress / completed / queued

the column target is              targets: [7]

function createStatusLabel(e, t) {
    var a = statuses[e].label || "label-default",
        s = '<span class="label ' + a + '">' + e + "</span>";
        s= '<span class="new badge '+ a +'" data-badge-caption="' + e + '"></span>';
    "Scheduled" != e && "Retrying" != e || (s = '<span class="label ' + a + '" data-toggle="tooltip" data-placement="top" data-html="true" title="' + ("Scheduled to send at " + t) + '">' + e + "</span>");
    return s
}


                    columnDefs: [{
                            orderable: false,
                            targets: "no-sort"
                        },
                        {
                            className: "color-sent",
                            targets: [2]
                        },
                        {
                            className: "color-opened",
                            targets: [3]
                        },
                        {
                            className: "color-clicked",
                            targets: [4]
                        },
                        {
                            className: "color-success",
                            targets: [5]
                        },
                        {
                            className: "color-reported",
                            targets: [6]
                        },
                        {
                            className: "status",
                                                render: function(e, t, a) {
                        return createStatusLabel(e, a[7])
                    },
                            targets: [7]
                        }
                    ],
                    order: [
                        [1, "desc"]
                    ]
                });
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros