mattiash/angular-tablesort

Issue with white space | ts-criteria

apank opened this issue · 3 comments

apank commented

This is my element {{organic['Average vol.']}}

I've tried:
ts-criteria="['Average vol.']|parseInt"
ts-criteria="'Average vol.'|parseInt"
ts-criteria="Average|parseInt"

but it doesn't work

Can you provide a more full code example for this? A sample of your data structure and the table code.

i5o commented

I guess it's never too late to reply?
https://code.angularjs.org/1.8.0/docs/error/$parse/syntax?p0=term&p1=is%20an%20unexpected%20token&p2=8&p3=Search%20term&p4=term

rows = [{'Search term': 'test'}]
    <table class="table" ts-wrapper>
      <thead>
        <tr>
          <th></th>
          <th ts-criteria="Search term">Search term</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="row in rows" ts-repeat ts-hide-no-data>
          <td><input type="checkbox" ng-model="row.selected" /></td>
          <td>{{row['Search term']}}</td>
        </tr>
      </tbody>
    </table>

Well, it's been a few years since I last used this but I'm pretty sure your property names can't contain whitespace like this. But you probably already know this since you're getting errors about exactly that.

I don't know what your data looks like, but your property name on the object should be what you are putting into the tableSort properties. Not the English text label.

Here's my suggested rewrite/example for you. Keep in mind this is untested and going off of my memory of how this works from years ago!

var rows = [
  {selected: false, searchTerm: "apple"},
  {selected: false, searchTerm: "mango"},
  {selected: false, searchTerm: "watermelon"}
];
<table class="table" ts-wrapper>
      <thead>
        <tr>
          <th></th>
          <th ts-criteria="searchTerm">Search Term</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="row in rows" ts-repeat ts-hide-no-data>
          <td><input type="checkbox" ng-model="row.selected" /></td>
          <td>{{row.searchTerm}}</td>
        </tr>
      </tbody>
    </table>

Perhaps you have data coming from the server with whitespace already in the JSON keys? If so you'll need to replace them with an underscore or something since this plugin can't handle whitespace.