esvit / ng-table

Simple table with sorting and filtering on AngularJS
http://esvit.github.io/ng-table
BSD 3-Clause "New" or "Revised" License
2.77k stars 851 forks source link

Working with nested json #126

Closed optikool closed 9 years ago

optikool commented 10 years ago

Hi,

First off great work!! You've included a lot of nice features. I'm having an issue with working with nested json content. I've tried different ways to apply filtering and sorting on columns that are being populated with nested content. For example, this is my json string...

[
    {
        "terrId": "id_111",
        "parentTerritoryID": "id_11",
        "parentTerritoryID1": "id_1",
        "parentTerritoryID2": "",
        "parentTerritoryID3": "",
        "parentTerritoryID4": "",
        "appId": "0013",
        "storeName": "Neon Orange-Red #00135555",
        "pendingStatus": 1,
        "territory": "Delta",
        "city": "Pawnee",
        "assignment": [
            {
                "dsPrsId": 1234,
                "lastName": "Picasso",
                "firstName": "Pablo",
                "assignmentRole": "OS ASC",
                "coverage": "Full Time",
                "lobs": [
                    {
                        "id": 1,
                        "type": "iPhone"
                    },
                    {
                        "id": 2,
                        "type": "iPad"
                    }
                ],
                "startDate": "Jan 1, 2013"
            },
            {
                "dsPrsId": 2345,
                "lastName": "van Gogh",
                "firstName": "Vincent",
                "assignmentRole": "ASC",
                "coverage": "Part Time",
                "lobs": [
                    {
                        "id": 2,
                        "type": "iPad"
                    },
                    {
                        "id": 3,
                        "type": "Mac"
                    }
                ],
                "startDate": "Jan 1, 2013"
            }
        ]
    }
]

First level key/value pairs work just fine when filtering and sorting. However I'm not able to figure out the correct syntax when dealing with second and third level pairs. Here is my html...

<table class="col-md-12 table" ng-table="assignmentsTableParams" show-filter="true" template-header="custom/header" template-pagination="custom/pager">
    <tr ng-repeat="activeAssignments in activeAssignmentsArray">                               
         <td data-title="'App Id'" filter="{ 'appId': 'text' }" sortable="'appId'">{{activeAssignments.appId}}</td>
        <td data-title="'Store Name'" filter="{ 'storeName': 'text' }" sortable="'storeName'"><a ng-href="#/details/{{store.appleId}}">{{activeAssignments.storeName}}</a></td>         
        <td data-title="'Territory'" filter="{ 'territory': 'text' }" sortable="'territory'">{{activeAssignments.territory}}</td>
        <td data-title="'City'" filter="{ 'city': 'text' }" sortable="'city'">{{activeAssignments.city}}</td>
        <td data-title="'Last, First Name'" filter="{ 'assignment[0].firstName': 'text' }" sortable="'activeAssignments.assignment[0].firstName'" ng-bind-html="formatName(activeAssignments.assignment)" class="tdDoubleRow"></td>
        <td data-title="'Role Type'" filter="{ 'assignmentRole': 'text' }" sortable="'assignmentRole'" ng-bind-html="formatRoleType(activeAssignments.assignment)" class="tdDoubleRow"></td>
        <td data-title="'Coverage'" filter="{ 'coverage': 'text' }" sortable="'coverage'" ng-bind-html="formatCoverage(activeAssignments.assignment)" class="tdDoubleRow"></td>
        <td data-title="'LOB'" filter="{ 'type': 'text' }" sortable="'type'" ng-bind-html="formatLob(activeAssignments.assignment)" class="tdDoubleRow"></td>                                           
        <td data-title="'Asgn. Start'" filter="{ 'startDate': 'text' }" sortable="'startDate'" ng-bind-html="formatAsgnStart(activeAssignments.assignment)" class="tdDoubleRow"></td>
    </tr>
</table>

Here is my JavaScript snippet...

/* Load Active Assignments Table */
    Staffing.getActiveAssignments(function(data) {
        $scope.activeAssignmentsArray = data;

        $scope.assignmentsTableParams = new ngTableParams({
            page: 1,            // show first page
            count: 10
        }, {
            total: data.length, // length of data
            getData: function($defer, params) {
                // filter sorting
                var orderedData = params.sorting() ?
                           $filter('orderBy')(data, params.orderBy()) :
                           data;
                // use build-in angular filter and filter search
                var orderedData = params.filter() ?
                       $filter('filter')(orderedData, params.filter()) :
                           orderedData;            

                $scope.activeAssignmentsArray = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());

                params.total(orderedData.length); // set total for recalc pagination
                $defer.resolve($scope.activeAssignmentsArray);
            }
        });
    });

As noted, the first four columns are on the first level of the json feed and work just fine with filtering and sorting. The problem is the second and third level content. Can you tell me if it's possible to filter sub level content and if so how would I go about this? Thanks in advance and good work.

asadabbas88 commented 10 years ago

Was there any progress on this issue or any good work around?

Sudhamsh commented 10 years ago

Any update on this issue? or Can I vote up for this feature some where?

sebastibe commented 10 years ago

I'm also up-voting on this one.

Nagendra1402 commented 8 years ago

Was there any work around for the issue?