javascript - jQuery datatables image sorting -


sorting jquery datables, pretty easy images having images , "-" bit difficult. manage string, date , int images can't think of anyway,

what want sort images , leave row has value "-" @ bottom,

http://jsfiddle.net/cyubv/73/

js

$.extend($.fn.datatableext.osort, {     "date-eu-asc": function (a, b) {         if (a == '-') return 1;         else if (b == '-') return -1;         else {             //return ((a < b) ? -1 : ((a > b) ? 1 : 0));             // going go here ?         }     },          "date-eu-desc": function (a, b) {         if (a == '-') return 1;         else if (b == '-') return -1;         else {             //return ((a < b) ? 1 : ((a > b) ? -1 : 0));             // going go here ?         }     } });  $('#table').datatable({     "aocolumns": [null, {         type: 'date-eu',         targets: 0     }] }); 

html

<table id="table">     <thead>         <tr>             <th>normal</th>             <th>image</th>         </tr>     </thead>     <tbody>         <tr>             <td>5</td>             <td data-order=2>                 <img src='http://t1.gstatic.com/images?q=tbn:and9gctu-gtas7b67ii3mmfairnqbdcinr9tnru31gakpqgq9zok7cjkfg' />             </td>         </tr>         <tr>             <td>-</td>             <td>-</td>         </tr>         <tr>             <td>10</td>             <td data-order=1>                 <img src='http://www.fancyicons.com/free-icons/112/must-have/png/16/stock_index_down_16.png' />             </td>         </tr>         <tr>             <td>20</td>             <td>-</td>         </tr>     </tbody> </table> 

i made work myself now,

http://jsfiddle.net/cyubv/76/

html

<table id="table">     <thead>         <tr>             <th>normal</th>             <th>image</th>         </tr>     </thead>     <tbody>         <tr>             <td>5</td>             <td data-order=2>                 <img src='http://t1.gstatic.com/images?q=tbn:and9gctu-gtas7b67ii3mmfairnqbdcinr9tnru31gakpqgq9zok7cjkfg' />             </td>         </tr>         <tr>             <td>-</td>             <td data-order='-'>-</td>         </tr>         <tr>             <td>10</td>             <td data-order=1>                 <img src='http://www.fancyicons.com/free-icons/112/must-have/png/16/stock_index_down_16.png' />             </td>         </tr>         <tr>             <td>20</td>             <td data-order='-'>-</td>         </tr>     </tbody> </table> 

js

$.extend($.fn.datatableext.osort, {     "date-eu-asc": function (a, b) {         if (a == '-') return 1;         else if (b == '-') return -1;         else {             return ((a < b) ? -1 : ((a > b) ? 1 : 0));         }     },          "date-eu-desc": function (a, b) {         if (a == '-') return 1;         else if (b == '-') return -1;         else {             return ((a < b) ? 1 : ((a > b) ? -1 : 0));         }     } });  $('#table').datatable({     "aocolumns": [null, {         type: 'date-eu',         targets: 0     }] }); 

added data-order = "-" rows want keep @ bottom.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -