Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to export jqgrid data with currency format like $4,355.

My colmodel is below. I am calling function like 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] + "	";
    }
}
html = html + "
"; // 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]] + "	"; // output each Row as
            // tab delimited
        }
    }
    html = html + "
"; // output each row with end of line
}
html = html + "
"; // 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();

   }

Any suggestions? Is there any possibility to get the row data with formatted value?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

Finally I got it. I used some tricks, but it is working great. I identified all money values by using their decimal places and formatted that value. Hence i got $ symbol on all monsy values. I knew it's not an optimal solution. But may be useful for someone.

var RE = new RegExp(/^d*.dd$/);           //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]] + "	"; // output for money each Row as
                // tab delimited
           } else {
               html = html + data[colNames[j]] + "	"; // output each Row as
                // tab delimited
           }
        }
    }
    html = html + "
"; // output each row with end of line
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...