6

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> 

2 Answers 2

9

This worked for me:

<table>
<thead>
...
</thead>
<tbody>
...
</tbody>
<tfoot>
    <tr class="no-sort">
        <td>...</td>
        <td>...</td>
    </tr>
</tfoot>
</table>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @webster !! But this question is from 2016 so... :)
0

From the documentation for columnDefs.targets option:

... class name will be matched on the TH for the column (without a leading .)

So you have to apply class datatable-nosort to the TH element in the header.

Another error occurs most likely because DataTables do not support colspan or rowspan in table body. To show extra details, use child row functionality instead.

1 Comment

Reading the title of the question might be useful: Exclude Row from sorting - Datatables.net

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.