Giter VIP home page Giter VIP logo

knockoutsort's Introduction

knockoutsort

generic knockout sorter that works.

We tried using jquery table sorter using knockout binding but when the data in the table data is dynamic, the table wont get sorted with refreshed data. We tried multiple ways to overcome this issue and we thought this would be the most generic solution.

Implementation :

on th you need the following data bind

data-bind="knockoutSort: { arr: FilteredSubjects, prop: 'Name' }"

arr can be an knockout ObservableArray or a pureComputed and prop is the property in the array to sort on

change your foreach loop to

data-bind="foreach:FilteredSubjects.sorted"

full example code below :

                            <table class="mdl-data-table mdl-js-data-table pt-width-full pt-data-table--main">
                                <!--table header-->
                                <thead>
                                    <tr>
                                        <th class="mdl-data-table__cell--non-numeric" data-bind="knockoutSort: { arr: FilteredSubjects, prop: 'Name' }">Name</th>
                                        <th data-bind="knockoutSort: { arr: FilteredSubjects, prop: 'Description' }">Description</th>
                                        <td>Actions</td>
                                    </tr>
                                </thead>
                                <!--end of table header-->
                                <!--table body-->
                                <tbody data-bind="foreach:FilteredSubjects.sorted">
                                    <tr>
                                        <td data-bind="text:Name"></td>
                                        <td data-bind="text:Description"></td>
                                        <td>
                                            <button class="mdl-button mdl-js-button mdl-button--mini-icon pt-button--mini-icon pt-text-blue--light mdl-typography--text-uppercase pull-right pt-margin-left-16" data-upgraded=",MaterialButton" data-bind="click:function(){ $parent.AddEditSubject($data); return false;}, text: (IsActive() ? 'Edit Me': 'Activate Me')">
                                                <i class="material-icons">mode_edit</i> Edit Me
                                            </button>
                                        </td>
                                    </tr>
                                </tbody>
                                <!--end of table body-->
                            </table>
                            <!--end of table-->

by David Vivash and Venkata Tata

knockoutsort's People

Contributors

vkctata avatar

Stargazers

Gowthami Gurapadi avatar

Watchers

DavidVivash avatar Gowthami Gurapadi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.