Question: Sort column by value other than cell content


Sort column by value other than cell content

Answers 2
Added at 2016-12-25 10:12

I'm using jQuery DataTables and I have one column that looks like shown below:

<td><span class="badge"> 123 </span>  <span> customer name </span></td>

i.e, I put first some number (ID), then the actual name which I want to sort by.

How can I tell jQuery DataTables to sort correctly by customer name?

nr: #1 dodano: 2016-12-25 15:12

Use data-order attribute on td element as shown in this example.

<td data-order="customer name">
   <span class="badge"> 123 </span>  
   <span> customer name </span>
nr: #2 dodano: 2016-12-27 03:12

You can do this with jQuery.

<table id="example" cellspacing="0" width="100%">
            <td data-search>Paul</td>
            <td data-search>Nickson</td>
<script src=""></script>
<script type="text/javascript" charset="utf8" src="jquery.dataTables.min.js"></script>
     $(document).ready(function() {
     } );

You have to add jquery.dataTables.min.js after including the jquery. You can find more about this here

Source Show
◀ Wstecz