drvic10k / bootstrap-sortable

adding sorting ability to bootstrap table
MIT License
513 stars 131 forks source link

Can't sort percentages if digit count is different (1%, 2%) any suggestions? #62

Closed yuchant closed 8 years ago

yuchant commented 9 years ago

I'm curious if there's a solution to this problem?

Can reproduce easily via latest download as of today.

Currently am using data-value and using integers.

<table class="sortable table">
  <thead>
    <tr>
      <th>foo</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1%</td>
    </tr>
    <tr>
      <td>4%</td>
    </tr>
    <tr>
      <td>10%</td>
    </tr>
    <tr>
      <td>15%</td>
    </tr>
    <tr>
      <td>9%</td>
    </tr>
    <tr>
      <td>1%</td>
    </tr>
  </tbody>
</table>
drvic10k commented 9 years ago

you can provide data-value attribute to the <td> elements and that will be used instead of auto generating it from the content

so your HTML will look like this:

<table class="sortable table">
  <thead>
    <tr>
      <th>foo</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td data-value="1">1%</td>
    </tr>
    <tr>
      <td data-value="4">4%</td>
    </tr>
    <tr>
      <td data-value="10">10%</td>
    </tr>
    <tr>
      <td data-value="15">15%</td>
    </tr>
    <tr>
      <td data-value="9">9%</td>
    </tr>
    <tr>
      <td data-value="1">1%</td>
    </tr>
  </tbody>
</table>
yuchant commented 9 years ago

Thank you that is what I've been doing. Wished it could parse!

drvic10k commented 9 years ago

I will leave this open, it could be nice feature to provide regex for creating data-value attributes from text in cells