jQuery对页面加载排序不会按领先的货币符号排序 [英] jQuery on page load sorting will not sort with leading currency symbol

查看:123
本文介绍了jQuery对页面加载排序不会按领先的货币符号排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的上一个问题中尝试在页面加载时对表进行排序,而没有任何客户端表排序切换开关,因此,当用户到达页面时,表将被排序。

In my previous question I was trying to sort a table on page load without any client side table sorting toggle switches just so the table would be sorted for a user as they arrive on the page.

问题得到了回答,我得到了一个很好的反应,并认为我解决了这个问题,所以我去睡觉,因此我试图使用我的网站上的代码今天,我意识到排序技术不工作,但在jsfiddle < a href =https://jsfiddle.net/ghzch66e/12/ =nofollow> https://jsfiddle.net/ghzch66e/12/ 。

The question was answered and I got a pretty good response and thought i'd solved the issue so I went to sleep, so as I tried to use the code on my website today I realized the sorting technique is not working but works perfectly in jsfiddle https://jsfiddle.net/ghzch66e/12/.

因此,我意识到表格不会在我的网站上排序,因为在网页上数据包含前导符号(£)符号 https://jsfiddle.net/ghzch66e/13/

So I then realized the table wont sort on my website because on the webpage the data contains a leading (£) symbol https://jsfiddle.net/ghzch66e/13/.

如何使用引号(£)符号。

How can I make the table sort even with a leading (£) symbol.

jQuery(document).ready(function(e) {
var dataRows = [];

//Create an array of all rows with its value (this assumes that the amount is always a number.  You should add error checking!!  Also assumes that all rows are data rows, and that there are no header rows.  Adjust selector appropriately.
$('#internalActivities > tbody > tr').each(function(i,j) {
   dataRows.push({'amount': parseFloat($(this).find('.amount').text()), 'row': $(this)});
})

//Sort the data smallest to largest
dataRows.sort(function(a, b) {
   return a.amount - b.amount;
});

//Remove existing table rows.  This assumes that everything should be deleted, adjust selector if needed :).
$('#internalActivities').empty();

//Add rows back to table in the correct order.
dataRows.forEach(function(ele) {
   $('#internalActivities').append(ele.row);
})
});


推荐答案

到数组

$('#internalActivities > tbody > tr').each(function(i,j) {
        dataRows.push({'amount': parseFloat($(this).find('.amount').text().replace(/£/,"")), 'row': $(this)});
      })

这篇关于jQuery对页面加载排序不会按领先的货币符号排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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