Sort Table but get Sorting Type (or value) from HTML instead if JS

Sort Table but get Sorting Type (or value) from HTML instead if JS

somedatatablesusersomedatatablesuser Posts: 7Questions: 0Answers: 0
edited August 2013 in General
Hi there,

i'm tryimg to set "sort-values" in the html-code. like:
[code]
hans meier
[/code]

is that possible with datatables or does anyone know a plugin that can do this?
thank you a million for your help.

Replies

  • somedatatablesusersomedatatablesuser Posts: 7Questions: 0Answers: 0
    no ideas? none? not possible? how do you sort your html-td-values?
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    It is possible in DataTables 1.10 as a new feature. 1.10 is pre beta, but stable. Its just missing documentation.

    Unfortunately the HTML attribute sorting is one of the examples I've yet to write, but you can tinker in the DataTables source if you want. The `data-sort` attribute will be automatically found and used. See the commit for more:

    https://github.com/DataTables/DataTables/commit/5cecbb5
    https://github.com/DataTables/DataTables/commit/0f2cc15

    Allan
  • somedatatablesusersomedatatablesuser Posts: 7Questions: 0Answers: 0
    Thanks a lot. I'll try that.
  • somedatatablesusersomedatatablesuser Posts: 7Questions: 0Answers: 0
    I tried this:
    1.) update dataTables to this version 1.10.0-dev:
    2.) add html-tag like this:
    [code]hans meier[/code]

    not working :-(
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    I would return "names" data in two fields: full name for display, last name for sorting by a hidden column.
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    @somedatatablesuser - can you link me to the page you are using please? That should work okay.

    Allan
  • somedatatablesusersomedatatablesuser Posts: 7Questions: 0Answers: 0
    the page runs offline but i made a jsfiddle:
    http://jsfiddle.net/xE8Z2/
    Column "Tel." should use the same sorting values as "Vorname"
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    You've got HTML in the last column, so DataTables sorts it as a string. You can use this plug-in: http://datatables.net/plug-ins/sorting#numbers_html - or if you are feeling brave, grab 1.10 from git as 1.10 has this sorting type built in. 1.10 is pre-beta at the moment.

    Allan
  • somedatatablesusersomedatatablesuser Posts: 7Questions: 0Answers: 0
    Sorry, it's not about numbers. How can I make DataTables use the HTML-field "data-sort"?
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Sorry - baby brain...

    You were using an old version of the 1.10 code, but even the latest had a small issue. I've just fixed is and the source file is here: http://datatables.net/dev/knockout/js/jquery.dataTables.js

    Your example updated: http://jsfiddle.net/xE8Z2/1/

    Allan
  • somedatatablesusersomedatatablesuser Posts: 7Questions: 0Answers: 0
    great! it works! thank you! there's also another annoying bug fixed. so thank you very much!
This discussion has been closed.