排序标题被点击时ngTable不起作用 [英] Sorting ngTable doesn't work when heading gets clicked

查看:169
本文介绍了排序标题被点击时ngTable不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在上需要一些排序表。由于该项目采用了棱角分明(v1.2.12)我开始使用 ngTable 模块(V0。 3.2)。

默认排序是标题,但一年也可以用作排序选项。当我加载页面它工作正常,但是当我点击表格的标题栏中单击整理得到,但排序没有反映在头,还排序参数不再设置。

当我开始调试我看到params.sorting()返回:的 {标题:未定义} 的从那一刻起,也不再可能点击可排序头,它只是没有按'做T什么了。

我想我失去了一些东西,似乎无法找到什么,虽然

我的数据如下:

  [{
    年:2014年,
    头衔:金题
},{
    年:2013年,
    头衔:金题
},{
    年:2013年,
    头衔:另一个称号
},{
    年:2014年,
    头衔:Whetshoverwerd xsade AAS
},{
    年:2013年,
    头衔:再创辉煌称号
},{
年:2013年,
    头衔:无论何时我SOAP
}]

视图:

 <表NG表=tableParams级=表>
    <&TBODY GT;
        < TR NG重复=文档中的$ DATA>
            < TD数据标题=年排序=年> {{document.year}}< / TD>
            < TD数据标题=标题排序='称号'>< A HREF =#> {{document.title时}}< / A>< / TD>
        < / TR>
    < / TBODY>
< /表>

该视图是一个指令,

  angular.module('appDirectives')。指令(myModuleDirective',函数(){
    //编译过程中运行
    返回{
        限制:'E',
        templateUrl:'路径/要/ view.html',
        更换:真实,
        控制器:函数($范围,$超时,$过滤器,TitleList,ngTableParams){            $ scope.tableParams =新ngTableParams({
                页面:1,//显示第一页
                数:10,//每页计
                排序:{
                    标题:ASC//初始排序
                }
            },{
                总:数据0,//长度
                的getData:函数($延迟,则params){
                    TitleList.get({}功能(数据){
                        VAR orderedData = params.sorting()?
                            $滤波器('ORDERBY')(数据,params.orderBy()):
                            数据;                        params.total(orderedData.length);
                        orderedData = orderedData.slice((params.page() - 1)* params.count(),params.page()* params.count());
                        $ defer.resolve(orderedData);
                    });
                }
            });
        }
    };


解决方案

这个问题尚不清楚,但是我在使用ngTable的v0.3.1的例子和我使用v0.3.2。该问题是由开始使用旧版本解决了。

I'm currently working on a table that requires some sorting. Since the project is using Angular (v1.2.12) I started using the ngTable module (v0.3.2).

The default sorting is the title but the year can also be used as sorting option. When I load the page it works fine, but when I click a table heading the clicked column gets sorted but the sorting is not reflected in the header, also the sorting param is no longer set.

When I start debugging I see that the params.sorting() returns: {title: undefined} From that moment it also is no longer possible to click on a sortable header, it just doesn't do anything anymore.

I think I'm missing something, can't seem to find what though

My data is as follows:

[{
    "year": 2014,
    "title": "Golden title"
}, {
    "year": 2013,
    "title": "Golden title"
}, {
    "year": 2013,
    "title": "Another title"
}, {
    "year": 2014,
    "title": "Whetshoverwerd xsade  aas"
}, {
    "year": 2013,
    "title": "Another brilliant title"
}, {
"year": 2013,
    "title": "Wherever I may SOAP"
}]

The view:

<table ng-table="tableParams" class="table">
    <tbody>
        <tr ng-repeat="document in $data">
            <td data-title="'Year'" sortable="'year'">{{document.year}}</td>
            <td data-title="'Title'" sortable="'title'"><a href="#">{{document.title}}</a></td>
        </tr>
    </tbody>
</table>

The view is a directive,

angular.module('appDirectives').directive('myModuleDirective', function () {
    // Runs during compile
    return {
        restrict: 'E',
        templateUrl: 'path/to/view.html',
        replace: true,
        controller: function ($scope, $timeout, $filter, TitleList, ngTableParams) {

            $scope.tableParams = new ngTableParams({
                page: 1, // show first page
                count: 10, // count per page
                sorting: {
                    title: 'asc' // initial sorting
                }
            }, {
                total: 0, // length of data
                getData: function ($defer, params) {
                    TitleList.get({}, function (data) {
                        var orderedData = params.sorting() ?
                            $filter('orderBy')(data, params.orderBy()) :
                            data;

                        params.total(orderedData.length);
                        orderedData = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
                        $defer.resolve(orderedData);
                    });
                }
            });
        }
    };

解决方案

The issue is not yet clear to me however, the examples at ngTable use v0.3.1 and I use v0.3.2. The issue was solved by starting to use the older version.

这篇关于排序标题被点击时ngTable不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆