Convert diplayed data

Convert diplayed data

mikedmasonmikedmason Posts: 39Questions: 12Answers: 0

Hi,
Is there a way to convert the data while using Editor. For example we store the data in pounds but we want to display it in tons. So I would like to convert the field by dividing by 1000. (this would not be field they would edit but just see). Thanks for the input.

DataTables debugger link
http://debug.datatables.net/ohesoy

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    You can use fields.data to convert, but you need to be very careful with that parameter as a function as it is a setter as well. i.e. consider:

    data: 'myProperty'
    

    As a function you would need to write:

    function ( row, type, set ) {
      if ( type === 'set' ) {
        row.myProperty = set;
      }
      return row.myProperty;
    }
    

    So yes, possible. but if you can put the data you want to edit into the data source, you might find that easier.

    Allan

  • mikedmasonmikedmason Posts: 39Questions: 12Answers: 0

    Thanks Allan. I will give it a go.

  • mikedmasonmikedmason Posts: 39Questions: 12Answers: 0
    edited March 2015

    Thanks Allan, that worked perfectly

    { data: null, render: function (data,type,row) {
                                    return (data.width / 16).toFixed(2);
                                }
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Just to confirm for anyone else reading this, it looks like the code above is applied to DataTables (columns.data and columns.render) rather than Editor which does not (currently) have a fields.render option (it might, or might not in future - haven't decided yet!).

    Allan

This discussion has been closed.