3

I am looking forward for custom sorting in ngtable, but according to http://ng-table.com/#/
replacing default sorting algorithm with a custom sort is still pending. In my case, I want to sort dataset with respect to days of week i.e, from starting from Monday and ending at Sunday.

Is there any way to do this?

Any kind of help and suggestions will be appreciated.

1 Answer 1

1

On your day, you could have a column display one property and actually sort on another. I would suggest having an object with dayName and daySort, where dayName would be the day of the week ("Monday") and the daySort would be the sort order (1). See the working CodePen below.

http://codepen.io/storytimesolutions/pen/NNdvzO

Table:

<table ng-table="demo.tableParams" show-filter="true" class="table table-bordered table-striped">
      <tr ng-repeat="row in $data track by row.id">
        <td title="'Day of the Week'" filter="{dayName: 'text'}" sortable="'daySort'">{{row.dayName}}</td>
        <td title="'Workout'" filter="{workoutPlan: 'text'}" sortable="'workoutPlan'">{{row.workoutPlan}}</td>
      </tr>
</table>

Stubbed Data:

data: [
        {id: 1, dayName: "Monday", daySort: 1, workoutPlan: "Run"},
        {id: 2, dayName: "Thursday", daySort: 4, workoutPlan: "Swim"},
        {id: 3, dayName: "Friday", daySort: 6, workoutPlan: "Jog"},
        {id: 4, dayName: "Friday", daySort: 6, workoutPlan: "Tennis"},
        {id: 5, dayName: "Saturday", daySort: 7, workoutPlan: "Volleyball"}
      ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.