format data from server

format data from server

chrisg123chrisg123 Posts: 9Questions: 4Answers: 0

I receive an 'amount' from the server as an integer (ex. 1000)
I know using the render method I can change its display format in the table, however, I would like to change the underlying value client side. (ex. amount/100) for all rows

How might I do this?

This question has an accepted answers - jump to answer

Answers

  • chrisg123chrisg123 Posts: 9Questions: 4Answers: 0
    edited July 2015

    Solved my own question:

    ajax: {
                url:myUrl,
                dataSrc: function(json){//format data from server here
                    for (var i=0,l=json.length; i<l; i++) {
                        val = json[i];
                        if(val.hasOwnProperty('amount')){
                            transaction.amount = transaction.amount/100;
                        }
    
                    }
                    return json;
                }...
    

    and if you are using editor:

     ajax: {
                url:"myEditorUrl",
                data: function(d){// convert back for server submit
                    d.data.amount = d.data.amount * 100;
                }...
    
     editor.on('postSubmit', function(e,json,data,action) {
            json.row.amount = json.row.amount /100;//convert response from server back again
    
        } );
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Thanks for posting back - that is absolutely how I would suggest doing it myself.

    Allan

This discussion has been closed.