我需要使用货币格式导出jqgrid数据,例如 $ 4,355 。
我的colmodel在下面。我正在调用像exportGrid('griddtable',[1,2,3,4,5])
name : 'totalSpend',
index : 'totalSpend',
align : 'right',
sorttype : 'number',
formatter : 'currency',
formatoptions : {
prefix : '$',
thousandsSeparator : ','
}
function exportGrid(table, filtered) {
var mya = new Array();
mya = $("#" + table).getDataIDs(); // Get All IDs
var data = $("#" + table).getRowData(mya[0]); // Get First row to get the
// labels
var colNames = new Array();
var ii = 0;
for ( var i in data) {
colNames[ii++] = i;
} // capture col names
var html = "";
for ( var k = 0; k < colNames.length; k++) {
if (filtered.indexOf(k) >= 0) {
html = html + colNames[k] + "\t";
}
}
html = html + "\n"; // Output header with end of line
for (i = 0; i < mya.length; i++) {
data = $("#" + table).getRowData(mya[i]); // get each row
for ( var j = 0; j < colNames.length; j++) {
if (filtered.indexOf(j) >= 0) {
html = html + data[colNames[j]] + "\t"; // output each Row as
// tab delimited
}
}
html = html + "\n"; // output each row with end of line
}
html = html + "\n"; // end of line at the end
var form = "<form name='csvexportform' action='exportData.do?method=excelExport' method='post'>";
form = form + "<input type='hidden' name='fileName' value='" + fileName
+ "'>";
form = form + "<input type='hidden' name='csvBuffer' value='" + html + "'>";
form = form + "</form><script>document.csvexportform.submit();</sc"
+ "ript>";
OpenWindow = window.open('', '');
OpenWindow.document.write(form);
OpenWindow.document.close();
}
有什么建议吗?是否有可能获得格式化值的行数据?
答案 0 :(得分:0)
最后我明白了。我使用了一些技巧,但效果很好。我通过使用小数位并使用格式化该值来识别所有货币值。因此我在所有monsy值上都有$符号。我知道这不是最佳解决方案。但对某人可能有用。
var RE = new RegExp(/^\d*\.\d\d$/); //Regular expression to find all 2 decimal values
for (i = 0; i < mya.length; i++) {
data = $("#" + table).getRowData(mya[i]); // get each row
for ( var j = 0; j < colNames.length; j++) {
if (filtered.indexOf(j) >= 0) {
if (RE.test(data[colNames[j]])) { //If matches add $symbol
html = html + "$" + data[colNames[j]] + "\t"; // output for money each Row as
// tab delimited
} else {
html = html + data[colNames[j]] + "\t"; // output each Row as
// tab delimited
}
}
}
html = html + "\n"; // output each row with end of line
}