Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Row from sorting - Datatables.net

I have a question about how to exclude a row(tr) from sorting. I want to make something like this http://jsfiddle.net/rishijagati/WwDg8/213/ but I don't want to set the data of the hidden row in jQuery. I suppose that you can do it adding a class to the <tr> element and after that manage to not sort this <tr> on initializing the datatable on jQuery. Actually I have the initialization like this:

$('.ordered_table').dataTable({
        "sPaginationType": "full_numbers",
        "dom": '<"toolbar">frtip',
        "pagingType": "numbers",
        "searching": false,
        "pageLength": 20,
        columnDefs: [{
          targets:  ['datatable-nosort'],
          orderable: false,  
          bsortable: false
        }],
        "aaSorting": []
 });

The class datatable-nosort is for not sorting on columns, this is not for rows.

Now is showing always this message, but I have made the accordion effect but the sorting is not working.

Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined

My table is like this:

<tr class="tr_tbody accordion">
   <td><%= order.id %></td>
   <td><%= order.created_at.strftime("%d/%m/%Y") %></td>
   <td><%= order.exhibitor_corporate_name %></td>
   <td><%= order.candidate_first_name %> <%= order.candidate_last_name %></td>
   <td><%= !order.engagements.first.nil? ? order.engagements.first.date.strftime("%d/%m/%Y") : ''   %></td>
   <td><%= !order.engagements.last.nil? ? order.engagements.last.date.strftime("%d/%m/%Y") : ''   %></td>
   <%
   number = @total_hours
   parts = number.to_s.split(".")
   result = parts.count > 1 ? parts[1].to_s : 0
   result = '0' + '.' + result.to_s
   hours = parts.count > 1 ? parts[0].to_s : 0
   %>
   <td class="datatable-nosort">
      <%= hours.to_s %>
      <%= 'h. ' %>
      <%= (result.to_f*60).to_i %>
      <%= 'm.' %> 
   </td>
   <td><%= @price_ngage %>€</td>
   <td></td>
</tr>
<tr >
   <td colspan="9">
   Order details
   </td>
</tr> 
like image 958
Paco Gómez Capón Avatar asked Nov 02 '16 14:11

Paco Gómez Capón


1 Answers

This worked for me:

<table>
<thead>
...
</thead>
<tbody>
...
</tbody>
<tfoot>
    <tr class="no-sort">
        <td>...</td>
        <td>...</td>
    </tr>
</tfoot>
</table>
like image 152
webster Avatar answered Oct 17 '22 21:10

webster