mercredi 15 juin 2016

How do you combine jquery UI selectable and sorting by header on the same table?

I'm trying to make a table that has both selectable rows and the ability to sort columns by header. So far I've succeeded in making the rows selectable. However, when I try to combine that with a table sorting plugin (I've tried half a dozen of them), the table sort never works. Either that, or the sorting plugin uses a id that conflicts with the selectable id. Does anyone have a method for table sorting by header that works with jquery UI selectable? Here is my code:

<html>
<body style="background: Lavender;">

  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">

  <style>
  #feedback { font-size: 1.4em; }
  #selectable .ui-selecting { background: AliceBlue!important; }
  #selectable .ui-selected { background: Snow!important; }
  #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  #selectable tr { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  th, td {
    text-align: left; border: 1px solid black; border-collapse: collapse;
  }
  </style>

  <script>
  $(function() {
    $( "#selectable" ).selectable({filter: 'tr:not(.disabled)'});
  });
  </script>

<table id="selectable" style="width:100%; border: 1px solid black; border-collapse: collapse;">
 <thead>
  <tr class='disabled' style="background: Gainsboro;">
    <th>Cat</th>
    <th>Dog</th>
    <th>Bird</th>
  </tr>
 </thead>
 <tbody>
  <tr style="background: skyblue;">
    <td>Russian Blue</td>
    <td>Beagle</td>
    <td>Hawk</td>
  </tr>
  <tr style="background: skyblue;">
    <td>British Shorthair</td>
    <td>Black Lab</td>
    <td>Blue Jay</td>
  </tr>
  <tr style="background: skyblue;">
    <td>Persian</td>
    <td>Pitbull</td>
    <td>Cardinal</td>
  </tr>
  <tr style="background: SkyBlue;">
    <td>Sphynx</td>
    <td>Poodle</td>
    <td>Crow</td>
  </tr>
 </tbody>
</table>

</body>
</html>

Please note that I'm not interested in jquery UI sorting, I need traditional sorting by clicking on the header for each column. Any ideas?

Aucun commentaire:

Enregistrer un commentaire