cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Untitled

A Pen By Captain Anonymous

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div ng-app>
    <div ng-controller="TableController">
         <h1>Complex Table Sorting Example</h1>
         <p>This is an example of using pure AngularJS 1.2.x code to generate a sortable table from an array of complex objects (using custom column ordering)</p>
         Full Blog Post <a href="" target="_blank">http://blog.idleworx.com</a>
      
      <!--<pre ng-bind="getFieldsSorted(items[0])|json"></pre> -->
      <!--<pre ng-bind="items|json"></pre> -->
      
        <hr>
        Sorting by column = {{toggles.sort.itemsSort.column}}, reverse = {{toggles.sort.itemsSort.reverse}}.
        <br>
        <table class="table table-striped" ng-if="items.length > 0">
            <thead>
                <tr>
                    <th ng-repeat="field in getFieldsSorted(items[0])" ng-click="toggles.sort.itemsSort.column='fields.'+field.name+'.value';toggles.sort.itemsSort.reverse=!toggles.sort.itemsSort.reverse;">{{field.description}}</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="i in items | orderBy:toggles.sort.itemsSort.column:toggles.sort.itemsSort.reverse">
                    <td ng-repeat="field in getFieldsSorted(i)">{{field.value}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
            
          
!
            
              app.module('idleworx',[]);

app.module('idleworx')
  .controller('TableController',TableController);

function TableController($scope) {

    $scope.toggles = {};
    $scope.toggles.sort = {};
    $scope.toggles.sort.itemsSort = {};

    $scope.toggles.sort.itemsSort.reverse = false;
    $scope.toggles.sort.itemsSort.column = null;

    $scope.getFieldsSorted = function (item) {
        var fields = _.sortBy(item.fields, 'order'); //using the awesome underscorejs library
        return fields;
    };

    $scope.items = [{
        "fields": {
            "link": {
                "description": "Link",
                    "name": "link",
                    "order": 1,
                    "value": "https://www.google.com"
            },
                "name": {
                "description": "Name",
                    "name": "name",
                    "order": 2,
                    "value": "Google Homepage"
            },
                "notes": {
                "description": "Notes",
                    "name": "notes",
                    "order": 4,
                    "value": "Notes about google"
            },
                "price": {
                "description": "Price",
                    "name": "price",
                    "order": 3,
                    "value": "100"
            }
        }
    }, {
        "fields": {
            "link": {
                "description": "Link",
                    "name": "link",
                    "order": 1,
                    "value": "http://www.yahoo.com"
            },
                "name": {
                "description": "Name",
                    "name": "name",
                    "order": 2,
                    "value": "Yahoo Homepage"
            },
                "notes": {
                "description": "Notes",
                    "name": "notes",
                    "order": 4,
                    "value": "Notes about yahoo"
            },
                "price": {
                "description": "Price",
                    "name": "price",
                    "order": 3,
                    "value": "200"
            }
        }
    }, {
        "fields": {
            "link": {
                "description": "Link",
                    "name": "link",
                    "order": 1,
                    "value": "http://www.altavista.com"
            },
                "name": {
                "description": "Name",
                    "name": "name",
                    "order": 2,
                    "value": "Altavista Homepage"
            },
                "notes": {
                "description": "Notes",
                    "name": "notes",
                    "order": 4,
                    "value": "Notes about altavista"
            },
                "price": {
                "description": "Price",
                    "name": "price",
                    "order": 3,
                    "value": "400"
            }
        }
    }



    ]; //end items
}
            
          
!
999px
Loading ..................

Console