DaysMonday

How to make one <td> element in <tr> not sortable (jquery ui)

I have a table like this

<table> <tr class="sortable"> <td>Days</td> <td>Monday</td> <td>Tuesday</td> <td>Wednesday</td> <td>Thursday</td> <td>Friday</td> <td>Saturday</td> </tr> <tr class="sortable"> <td>Works</td> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> </tr> </table> 

In this case, I do not want the <td> Days and Jobs not to be sorted, but to remain in a string.

+4
source share
3 answers

Make the line headers <th> as they should be, and include only the <td> elements.

 <table> <tr class="sortable"> <th>Days</th> <td>Monday</td> ... ​$( '​​​​.sortable' ).sortable({ items: 'td' });​​​​​ 

Demo: http://jsfiddle.net/Xugru/

+1
source

You can use the cancel option to do this:

 $('.sortable').sortable({ cancel: 'td:first' }); 

Here are the docs .

0
source
 <table> <tr class="sortable"> <td>Days</td> <td>Monday</td> <td>Tuesday</td> <td>Wednesday</td> <td>Thursday</td> <td>Friday</td> <td>Saturday</td> </tr> <tr class="sortable"> <td>Works</td> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> </tr> </table> 

Let the column id not be sortable.

 $(".sortable").sortable({ items: "td:not(:first)" }); 

It's all. All you need to do is exclude the first td in the elements.

Excellent day

0
source

All Articles