PHP echo makes table sort not work

PHP echo makes table sort not work

conciseconcise Posts: 13Questions: 5Answers: 0

We populate our DataTable with php files that display data that has been recorded. If you click on this page you will understand (the right column displays 'clicks by popularity').

https://www.concise-courses.com/hacking-tools/d.php

This right hand side column is populated by php strings that pull data regarding the amount of time a link has been clicked. We would like for that data to be sorted.....

The php/ javascript string that does this in each row is here:

ccount_display('windbg')

Do you think that there is a compatibility problem here? Can't the DataTables javascript read the php?

Thanks -

Answers

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    have you got a code snippet ?

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    Thanks for the link. The problem is this:

    <script type="text/javascript">ccount_display('windbg')</script>107

    DataTables will strip the HTML tags, but that leaves:

    ccount_display('windbg')107

    Which is not a number and hence it can't be sorted as such.

    I think the best bet here would be to use HTML5 orthogonal data. So for example make your HTML for that column:

    <td class="text-center sorting_1" data-order="107" data-type="107">
      <script type="text/javascript">ccount_display('windbg')</script>107 
    </td>
    

    i.e. same as before but add data-order and data-type so DataTables will use the number for type detection and ordering.

    Allan

  • conciseconcise Posts: 13Questions: 5Answers: 0

    Thanks Allan - as soon as I have an update on this I can update this thread too!

This discussion has been closed.