[英]How can I sort ip addresses on BIRT with JavaScript?
I'm a total newbie on BIRT and I'm not a javascript pro. 我是BIRT的新手,我不是javascript专业版。 I am using birt to create some reports by getting some information from my database.
我正在使用birt通过从我的数据库中获取一些信息来创建一些报告。 I have ip addresses on a column as strings.
我在列上有ip地址作为字符串。 BIRT provides a sorting section for tables and I have this expression right there;
BIRT为表提供了一个排序部分,我就在那里有这个表达式;
if(params["sorting"].value=="startdate")
dataSetRow["r_date_0"]
else if(params["sorting"].value=="enddate")
dataSetRow["r_date_1"]
else if(params["sorting"].value=="ipaddress")
dataSetRow["r_vchar_2"]
else
dataSetRow["r_vchar_3"]
this is working perfect for startdate and enddate, but when it comes to the ipaddresses, it compares them as string so in the sorted report, i see like '2' is bigger then '199'. 这对于startdate和enddate来说是完美的工作,但是当涉及到ipaddress时,它将它们作为字符串进行比较,因此在排序的报告中,我看到'2'比'199'大。
I could just split ip addresses with '.' 我可以用'。'拆分ip地址。 and parse them to integers and compare if i was working with python or java, but I'm not sure how to do this with javascript in BIRT environment.
并将它们解析为整数并比较我是否正在使用python或java,但我不确定如何在BIRT环境中使用javascript执行此操作。
Any ideas on how can i modify my expression to achieve my needs will be appreciated. 关于如何修改我的表达以实现我的需求的任何想法将不胜感激。
Use in your dataset a computed column, where you transform your ip-addresses in a form that they can be sorted, eg 在数据集中使用计算列,您可以在其中以可以对其进行排序的形式转换您的IP地址,例如
var addrArray = dataSetRow["r_vchar_2"].split(".");
var num = 0;
for (var i=0;i<addrArray.length;i++) {
var power = 3-i;
num += ((parseInt(addrArray[i])%256 * Math.pow(256,power)));
}
num;
You can use this field for sorting, and the original field for displaying ip-addresses 您可以使用此字段进行排序,并使用原始字段显示IP地址
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.