Editor transform vs. render data

Editor transform vs. render data

ahaighahaigh Posts: 6Questions: 2Answers: 1

All,

Quick and I suspect relatively easy question:

Is it possible to alter data directly prior to sending it to a table in Editor? I know that I can use a render function to change how the data is displayed, but this doesn't actually alter the data and if I need it for footers, other calculations, the render doesn't carry through.

For example:

        columns: [
            {data: "test","defaultContent": "$0", render: function ( data, type, row ) {return (data*2)}}
            ],

The code above will multiply whatever number is drawn by ajax by two, but any calculations based on the number in that column are still based on the original number.

I know I can do something like this and then use rows().every() to get the number that I need in the adjacent column but this isn't an ideal solution as it would require showing/hiding different columns which starts to make putting the footers in the right place a bit tricky.

columns: [
            { data: "test","defaultContent": "$0"},
            { data: undefined,"defaultContent": "$0"},
            ],

Also, while there are validators and formatters that can be used on the fields from the Editor ajax file, I'm not sure that this necessarily accomplishes the goal, and regardless returns a JSON error as written.

->fields(
        Field::inst( 'test' )
                 .getFormatter(function($val, $data){
                  return $val*2;
                  }))

Apologies if this isn't the first time this question has been answered, and if it isn't possible to do this directly I can accomplish the same goal with some server side programming. Any input or thoughts or prior examples would be appreciated.

Thank you!

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin
    Answer ✓

    If you want to get the rendered value you can use cells().render().

    Could you show me an example of what you are looking to do please? It sounds like you might be trying to sum numbers and then format them in the footer, but I'm not certain.

    Allan

  • ahaighahaigh Posts: 6Questions: 2Answers: 1

    I think I have it sorted out, but I may ping you with another question. Thanks again!

  • rossbobrossbob Posts: 29Questions: 4Answers: 0

    Hi guys, I think I'm trying to do a similar thing like this but I don't think the accepted answer suits. I have some free text data which has newlines chars in it. In my PHP, I string-replace the newline chars with <br/> strings. However, in the Editor modal, I want it to change the <br/> back to a newline char. Any thoughts on how to do this. I have tried a custom renderer on the attribute in the editor definition and that did not seem to work. Thanks for the help guys.

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin
    Answer ✓

    Don't do any replacement until, and only for, the output. You want to store and edit the text with newline characters and then when you do the output (in a table or whatever) do the replacement to br.

    Allan

  • rossbobrossbob Posts: 29Questions: 4Answers: 0

    Wow. Can't believe I missed that! Thanks.

This discussion has been closed.