-2

I have an object like this

a: 25.165562913907287
b: 25.274725274725274
c: 36.633663366336634
d: 2.6128266033254155
e: 55.52147239263804
f: 78.52941176470588
g: "xxx"
id: 6

now I want to use angular js to show a table with header from 'a' to 'g', exclude the field 'id', and also show all value from 'a' to 'g', exclude field id, neither How can I achieve that ?

****Note**: I don't want to filter by value of the property but the property itself, what I did was a filter return empty string if the field was equal 'id', and looking for a better solution

  • what you have done so far? – xkeshav Jun 29 '16 at 03:56
  • Possible duplicate of [How to filter by object property in angularJS](http://stackoverflow.com/questions/17793751/how-to-filter-by-object-property-in-angularjs) – Sherly Febrianti Jun 29 '16 at 04:00
  • try to see this : > http://stackoverflow.com/questions/17793751/how-to-filter-by-object-property-in-angularjs – Sherly Febrianti Jun 29 '16 at 04:08
  • I don't want to filter by value of the property but the property itself, what I did was a filter return empty string if the field was equal 'id', and looking for a better solution – user3571374 Jun 29 '16 at 04:44

3 Answers3

1

Look at the code that's printing out the table and add an if condition to skip printing the column for id (slightly modifying gayathri's template code):

<table>
    <thead>
        <tr ng-repeat="item in arraylist | limitTo:1">
            <th ng-repeat="(key, val) in item" ng-if="key!='id'">
                <span>{{key}}</span>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="item in arraylist">
            <td ng-repeat="(key, val) in item" ng-if="key!='id'">
                {{val}}
            </td>
        </tr>
    </tbody>
</table>
offchance
  • 642
  • 7
  • 13
0

Let's assume all data from a to g and id is assign to some varibale named data

data: {
    a: 25.165562913907287
    b: 25.274725274725274
    c: 36.633663366336634
    d: 2.6128266033254155
    e: 55.52147239263804
    f: 78.52941176470588
    g: "xxx"
    id: 6
}

Now to exclude id and associated value with id,

var excludedIdObject = {};
angular.forEach(data, function(key) {
    if (data.id) {
        return;
    }
    excludedIdObject = key;
}
Varit J Patel
  • 3,497
  • 1
  • 13
  • 21
0

Hi refere this https://plnkr.co/edit/ZGula5MLLyQ8Wd9c26Yc?p=preview

use Omit in underscore omit the id first then use the table to display key dynamicaly and datas

   $scope.arraylist = [
        {
            "id": 1,
            "a": "jk",
            "b": "May 5",
            "c": "fgh",
            "d": "true",
            "e": "dfgdfg",
            "f": "M",
            "g": true,
            "h": "Profile"
        },
        {
            "id": 2,
            "a": "ghfgh",
            "b": "1 AM",
            "c": "true",
            "d": "true",
            "e": "false",
            "f": "47:11 AM",
            "g": "true",
            "h": "Profile"
        },
        {
            "id": 3,
            "a": "iyuiuy",
            "b": " AM",
            "c": "true",
            "d": "true",
            "e": "false",
            "f": "Ma AM",
            "g": "true",
            "h": "Profile"
        }
    ]
$scope.arraylist_duplicate = $scope.arraylist;
    angular.forEach($scope.arraylist_duplicate , function(todo, i)
    {
        delete todo.id
    });

HTML

<table>
      <thead>
        <tr ng-repeat="item in arraylist_duplicate | limitTo:1">
          <th ng-repeat="(key, val) in item" >
            <span>{{key}}</span>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="item in arraylist_duplicate ">
          <td ng-repeat="(key, val) in item">
            {{val}}
          </td>
        </tr>
      </tbody>
    </table>
Gayathri Mohan
  • 2,924
  • 4
  • 19
  • 25