您现在的位置是:首页 > 电脑 > 

角度表排序(Angular table sorting)

2025-07-22 05:10:20
角度表排序(Angular table sorting) 我需要通过点击表格标题来排序表格项目。 我的列值数字为字符串 。 所以排序并不是我想要的。 我知道我应该将我的字符串转换为浮动。 我需要逗号分隔符和双精度点。 我试着做parseFloat,但那不行。 例。 我想排序“12,456.00”,“45”,“ - 4.00”,“7.78”类型的字符串
角度表排序(Angular table sorting)

我需要通过点击表格标题来排序表格项目。 我的列值数字为字符串 。 所以排序并不是我想要的。 我知道我应该将我的字符串转换为浮动。 我需要逗号分隔符和双精度点。 我试着做parseFloat,但那不行。

例。 我想排序“12,456.00”,“45”,“ - 4.00”,“7.78”类型的字符串。 我分享了jsfiddle链接来解释我的场景。 http:///k4seL1yx/1/

function SortableTableCtrl() { var scope = this; scope.head = { a: "Poured", b: "Sold", c: "Loss" }; scope.body = [{"ID":"September-2016", "Product":"September-2016", "Poured":"111759.07", "Sold":"107660.97", "Loss":"-4098.10", "Variance":"-.67", "startDate":"2016-09-01", "endDate":"2016-09-22"}, {"ID":"ovember-2015", "Product":"ovember-2015", "Poured":"5690.25", "Sold":"5295.60", "Loss":"-76.65", "Variance":"-1.7", "startDate":"2015-11-20", "endDate":"2015-11-0"}, {"ID":"May-2016", "Product":"May-2016", "Poured":"156401.65", "Sold":"151192.51", "Loss":"-5209.14", "Variance":"-.", "startDate":"2016-05-0", "endDate":"2016-05-1"}, {"ID":"March-2016", "Product":"March-2016", "Poured":"49260.22", "Sold":"4999.14", "Loss":"18.92", "Variance":"0.28", "startDate":"2016-0-01", "endDate":"2016-0-09"}, {"ID":"June-2016", "Product":"June-2016", "Poured":"162126.88", "Sold":"161718.62", "Loss":"-408.26", "Variance":"-0.25", "startDate":"2016-06-01", "endDate":"2016-06-0"}, {"ID":"July-2016", "Product":"July-2016", "Poured":"160185.68", "Sold":"154882.40", "Loss":"-50.28", "Variance":"-.1", "startDate":"2016-07-01", "endDate":"2016-07-1"}, {"ID":"January-2016", "Product":"January-2016", "Poured":"55509.26", "Sold":"179696.72", "Loss":"-175812.54", "Variance":"-49.45", "startDate":"2016-01-01", "endDate":"2016-01-1"}, {"ID":"February-2016", "Product":"February-2016", "Poured":"150980.7", "Sold":"146248.72", "Loss":"-472.01", "Variance":"-.1", "startDate":"2016-02-01", "endDate":"2016-02-29"}, {"ID":"December-2015", "Product":"December-2015", "Poured":"16784.42", "Sold":"1672.95", "Loss":"-4110.47", "Variance":"-2.45", "startDate":"2015-12-01", "endDate":"2015-12-1"}, {"ID":"August-2016", "Product":"August-2016", "Poured":"16885.51", "Sold":"160024.84", "Loss":"-8828.67", "Variance":"-5.2", "startDate":"2016-08-01", "endDate":"2016-08-1"}] scope.sort = { column: 'b', descending: false }; scope.selectedCls = function(column) { return column == scope. && 'sort-' + scope.sort.descending; }; = function(column) { var sort = scope.sort; if ( == column) { sort.descending = !sort.descending; } else { = column; sort.descending = false; } }; }

I need to sort table items by clicking table header. My column values number as string. So sorting is not applying as I wish. I know I should convert my string into float. I need comma separator and double point precision as well. I tried to do parseFloat but that's not working.

Example. I want to sort "12,456.00", "45", "-4.00", "7.78" kind of strings. I shared jsfiddle link to explain my scenario. http:///k4seL1yx/1/

function SortableTableCtrl() { var scope = this; scope.head = { a: "Poured", b: "Sold", c: "Loss" }; scope.body = [{"ID":"September-2016", "Product":"September-2016", "Poured":"111759.07", "Sold":"107660.97", "Loss":"-4098.10", "Variance":"-.67", "startDate":"2016-09-01", "endDate":"2016-09-22"}, {"ID":"ovember-2015", "Product":"ovember-2015", "Poured":"5690.25", "Sold":"5295.60", "Loss":"-76.65", "Variance":"-1.7", "startDate":"2015-11-20", "endDate":"2015-11-0"}, {"ID":"May-2016", "Product":"May-2016", "Poured":"156401.65", "Sold":"151192.51", "Loss":"-5209.14", "Variance":"-.", "startDate":"2016-05-0", "endDate":"2016-05-1"}, {"ID":"March-2016", "Product":"March-2016", "Poured":"49260.22", "Sold":"4999.14", "Loss":"18.92", "Variance":"0.28", "startDate":"2016-0-01", "endDate":"2016-0-09"}, {"ID":"June-2016", "Product":"June-2016", "Poured":"162126.88", "Sold":"161718.62", "Loss":"-408.26", "Variance":"-0.25", "startDate":"2016-06-01", "endDate":"2016-06-0"}, {"ID":"July-2016", "Product":"July-2016", "Poured":"160185.68", "Sold":"154882.40", "Loss":"-50.28", "Variance":"-.1", "startDate":"2016-07-01", "endDate":"2016-07-1"}, {"ID":"January-2016", "Product":"January-2016", "Poured":"55509.26", "Sold":"179696.72", "Loss":"-175812.54", "Variance":"-49.45", "startDate":"2016-01-01", "endDate":"2016-01-1"}, {"ID":"February-2016", "Product":"February-2016", "Poured":"150980.7", "Sold":"146248.72", "Loss":"-472.01", "Variance":"-.1", "startDate":"2016-02-01", "endDate":"2016-02-29"}, {"ID":"December-2015", "Product":"December-2015", "Poured":"16784.42", "Sold":"1672.95", "Loss":"-4110.47", "Variance":"-2.45", "startDate":"2015-12-01", "endDate":"2015-12-1"}, {"ID":"August-2016", "Product":"August-2016", "Poured":"16885.51", "Sold":"160024.84", "Loss":"-8828.67", "Variance":"-5.2", "startDate":"2016-08-01", "endDate":"2016-08-1"}] scope.sort = { column: 'b', descending: false }; scope.selectedCls = function(column) { return column == scope. && 'sort-' + scope.sort.descending; }; = function(column) { var sort = scope.sort; if ( == column) { sort.descending = !sort.descending; } else { = column; sort.descending = false; } }; }

最满意答案

我为我的问题到了解决方案。 实际上我非常专注于将“倾倒,卖出,损失”从字符串转换为浮动。 但是为什么我不应该创建一个新列作为克隆,并且其格式是float。 parseFloat完成了魔术。 所以我可以使用Poured值进行表格显示,并使用pouringClone值进行排序。

//Initially I got the above scope.body only. To perform sorting I modified scope.body as like below scope.body.forEach(function(value) { value.pouredClone = parseFloat(value.Poured) value.soldClone = parseFloat(value.Sold) value.lossClone = parseFloat(value.Loss) value.varianceClone = parseFloat(value.Variance) });

这里是小提琴与解决方案的链接。 http:///q7mcu​​6fx/1/

I found a solution for my question. Actually I am very focused on convert "poured, sold, loss" from string to float. But why I should not create a new column as clone of this and the format of that is float. parseFloat done the magic. So I can use Poured value for table show and use pouredClone value for sorting on the behind.

//Initially I got the above scope.body only. To perform sorting I modified scope.body as like below scope.body.forEach(function(value) { value.pouredClone = parseFloat(value.Poured) value.soldClone = parseFloat(value.Sold) value.lossClone = parseFloat(value.Loss) value.varianceClone = parseFloat(value.Variance) });

Here is the link of fiddle with solution. http:///q7mcu6fx/1/

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/61862.html

相关标签:无
上传时间: 2023-04-21 00:31:17
留言与评论(共有 7 条评论)
本站网友 胡万进
1分钟前 发表
"May-2016"
本站网友 中国海关数据
24分钟前 发表
"49260.22"
本站网友 英语考级
28分钟前 发表
"-175812.54"
本站网友 像男人一样战斗
26分钟前 发表
"Loss"
本站网友 罗兰香谷
2分钟前 发表
"-2.45"
本站网友 vcl
10分钟前 发表
///k4seL1yx/1/ function SortableTableCtrl() { var scope = this; scope.head = { a