Angular JS:html 表列排序不起作用 [英] Angular JS : html table columns ordering not working

查看:21
本文介绍了Angular JS:html 表列排序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 angular-JS 中创建了一个应用程序,用于对表中的值进行排序.表中的某些列是动态的,是基于子 JSON 数组创建的

I've created an application in angular-JS for sorting values in tables. Certain columns in tables are dynamic and been created based on the child JSON array

例如,从服务返回的 JSON 结构位于主 JSON 的其他字段包含另一个 JSON 数组的结构中,该数组是附加列,

For example the JSON structure returning from a service is in the structure where the others field of the main JSON contains another JSON array which is the additional columns,

在下面的结构中
第一个对象有文件 4,
第二个对象有文件1文件2
第三个对象具有文件 2文件 3
第四个对象有 File 3File 4

In the below structure the
first object has File 4,
second object has File 1 and File 2,
third object has File 2 and File 3 and
fourth object has File 3 and File 4

所以总共会有四个额外的动态列,即文件 1、文件 2、文件 3、文件 4 每个对象都有对应文件字段的值,有时存在有时不存在.

so all together there will be four additional dynamic columns i.e File 1, File 2, File 3, File 4 each object has value for the corresponding File field, sometime present sometime not present.

<th ng-repeat="colms in getcolumns()"><a ng-click="sort_by("dont know wat to pass")">
              <i>{{colms}}</i>
            </a>
</th>

我已经完美地展示了带有动态列的表格,并且我已经使用 angular-js 实现了对每一列的排序.但问题是排序适用于除动态列之外的所有表列

I've shown the tables with the dynamic columns perfectly also I've implemented the sorting for each columns using angular-js. But the problem is that the sorting is working for all table columns except the dynamic columns

谁能告诉我一些解决方案

Can anyone please tell me some solution for this

下面给出了我的 JS-Fiddle

My JS-Fiddle is given below

演示

推荐答案

我知道您无法更改为您带来数据的服务,但您可以在将其放入控制器后对其进行转换.我为您创建了一个函数,该函数应该将您列表的另一列更改为以 id 为键、以 value 为值的各个列.

I understand you cant change the service that brings you the datas but you can transform it after you have it inside your controller. I created a function for you that should change your list's other column into individual columns having id as key and value as value.

$scope.transformDatas = function() {
    $scope.newDatas = [];
    for(var i in $scope.datas) {
        var auxData = {};
        angular.forEach($scope.datas[i], function(value, key) {
            if(key != 'others')
                auxData[key] = value;
            else {
                for(var j in $scope.datas[i].others) {
                    var nth = 1;
                    while(auxData[$scope.datas[i].others[j].id + ',' + nth] != undefined)
                        nth++;
                    auxData[$scope.datas[i].others[j].id + ',' + nth] = $scope.datas[i].others[j].value;
                }
            }
        });
        $scope.newDatas.push(auxData);
    }
}

从这里到您的目标,这很容易,您已经完成了(对普通字段进行排序).

From here to your goal it's easy job, you already done it (sorting the normal fields).

小提琴 http://jsfiddle.net/KR6Xh/15/

这篇关于Angular JS:html 表列排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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