question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sort by custom data attribute on a <td>?

See original GitHub issue

Hi, I read a couple issues about people trying to do (I think) the same thing I am: #500, #546.

I am creating an html table, and I want to sort a column by a custom attribute instead of the actual contents of the . Is there a way to do this?

I thought this is what data-sort-name column option is for, but I can’t get it to work.

For example:

<table data-toggle="table"
    >
    <thead>
        <tr>
            <th data-field="fruit" data-sortable="true">Item</th>
            <th data-field="date"  data-sortable="true" data-sort-name="month">Date</th>
            <th data-field="type"  data-sortable="true">Type</th>
        </tr>
    </thead>
    <tbody>
        <tr><td>Pear  </td><td data-month="1">January</td> <td>Fruit</td></tr>
        <tr><td>Carrot</td><td data-month="3">March</td>   <td>Vegetable</td></tr>
        <tr><td>Apple </td><td data-month="2">February</td><td>Fruit</td></tr>
    </tbody>
</table>

When I click the “Date” header, I want it to sort by the numerical data-month attribute (1, 2, 3) rather than the text value (January, February, March).

Is this possible?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
moussa1commented, Apr 2, 2016

@Aabling @zkan Were you able to figure out a workaround for this issue?

2reactions
moussa1commented, Apr 2, 2016

@wenzhixin Can you please answer Aabling and zkan? I have the same issue and cannot seem to find a solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding data-order attribute value in <td> tag for custom ...
Try using .sort() method, and define your own sorting logic to sort the table rows as desired... developer.mozilla.org/en-US ...
Read more >
Order by custom data attribute
I wanted to introduce a click event that would sort the table based on the data-paramX I am not sure if this is...
Read more >
Bootstrap Table-Sort by custom data attribute
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Read more >
How to sort HTML elements by data-attribute
In this article, we sort the unordered list elements using the data attribute with variable values on which the elements are to be...
Read more >
custom-data-attribute - datatables - html - jquery - sorting
Html – Custom sorting on values in a data-sort attribute with Jquery Datatables · Best Solution · Related Solutions ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found