alalonde / angular-scrollable-table

A fixed header table directive for AngularJS
MIT License
68 stars 48 forks source link

Nested properties in sortable headers #4

Closed jmaynier closed 10 years ago

jmaynier commented 10 years ago

Only direct properties are supported for sortable headers, we have to create a comparator function for every nested property.

Example: with a collection containing nested objects like: [{name:"ABC", birth:{date:'2000-01-01", place:"NY"}}, {name:"XYZ", birth:{date:'2010-01-01", place:"Spain"}}]

 <scrollable-table watch="people">
    <table>
        <thead>
            <tr>
                <th  sortable-header col="name">Charterer</th>
                <th  sortable-header col="birth.date">Birth</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="people">
                <td>{{name}}</td>
                <td>{{birth.date}}</td>
            </tr>
         </tbody>
      </table>
 </scrollable-table>

will not work. The code should parse the col attribute for dot.

alalonde commented 10 years ago

Yes, that was by design (I didn't need anything more complicated than a direct property), but parsing an expression would have greater utility. I will think of an appropriate expression syntax and implement it.

alalonde commented 10 years ago

I added an additional attribute to the sortable-header directive to support this. You can add 'on' with an expression as the value, such as:

on="birth.date" on="birth.date | date:'yyyy'"

See an example here: http://jsfiddle.net/6mXt5/4/

jmaynier commented 10 years ago

Thanks for the quick fix !