ng-Table排序效果不佳

时间:2016-04-16 15:15:07

标签: angularjs ngtable

我使用ng-Table创建了一个应用程序,应用程序工作正常,使用ng-Table生成了表。我面临的问题是表排序不起作用。我的代码如下所示

HTML:

 <table ng-table="tableParams" class="table">
    <tr ng-repeat="user in $data">
        <td data-title="'Name'" sortable="'name'">
            {{user.name}}
        </td>
        <td data-title="'Age'" sortable="'age'">
            {{user.age}}
        </td>
    </tr>

和我的js代码:

 var app = angular.module('myApp', ['ngTable']).
controller('mycontroller', function($scope, NgTableParams) 
{
 var data = [{name: "Moroni", age: 50},
            {name: "Tiancum", age: 43},
            {name: "Jacob", age: 27},
            {name: "Nephi", age: 29},
            {name: "Enos", age: 34},
            {name: "Tiancum", age: 43},
            {name: "Jacob", age: 27},
            {name: "Nephi", age: 29},
            {name: "Enos", age: 34},
            {name: "Tiancum", age: 43},
            {name: "Jacob", age: 27},
            {name: "Nephi", age: 29},
            {name: "Enos", age: 34},
            {name: "Tiancum", age: 43},
            {name: "Jacob", age: 27},
            {name: "Nephi", age: 29},
            {name: "Enos", age: 34}];

$scope.tableParams = new NgTableParams({
    sorting: {
        name: 'asc'     
    }
}, {
    getData: function($defer, params) {
        $defer.resolve(data);
    }
});
});

是否有任何错误?

4 个答案:

答案 0 :(得分:3)

这样可行,您需要为数据添加$ filter。

libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadXML( $xml_file);
$imgs = ...(get the imgs to extract the src...('img') ??;

//Then run a possible foreach
//something like:

foreach($imgs as $img){

   $src= ///the src of the $img

   //try it out
   echo '<img src="'.$src.'" /> <br />',
}

答案 1 :(得分:1)

试试这个

<table ng-table="tableParams" class="table">
    <tr ng-repeat="user in $data | orderBy:'-age'"">
        <td data-title="'Name'">
            {{user.name}}
        </td>
        <td data-title="'Age'">
            {{user.age}}
        </td>
    </tr>

OR

    <table class="table">
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
    <tr ng-repeat="user in $data | orderBy:'-age'">
      <td>{{user.name}}</td>
      <td>{{user.age}}</td>
    </tr>
  </table>

答案 2 :(得分:1)

你试过Smart table吗?它是一个Angularjs模块,可以在表格中轻松显示数据,其中包含一系列内置功能,如过滤,排序等:

http://lorenzofox3.github.io/smart-table-website/#section-intro

使用简单,看起来很棒!

答案 3 :(得分:1)

试试这个。在ngTable文档中使用这种方式将数据绑定到表。

$scope.tableParams = new NgTableParams({
sorting: {
    name: 'asc'     
 }
}, {
dataset: data
});