Fill the field via another field

Fill the field via another field

antoniocibantoniocib Posts: 277Questions: 62Answers: 1

Hello everybody,

I would need to bind the value to a field via another field, example:

Row A:
Field 8: "SA"

Field 9: "Campania"

I try in this mode but dont work:

            {
                "data": "prov_destinatario"
            },
            {
                "data": "tratta",
            render: function ( data, type, row ) {
                        if ( data.prov_destinatario == "SA"  ) {
                                return 'Campania';
                        }
                        else if (data.prov_destinatario == "TE") {
                            return 'Adriatico';
                        }
                },
            className: "dt-body-center",

            }

Can help me pls?

Answers

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    edited February 2022

    Did you check the content of "data", "type" and "row" in you debugger? Should be easy to figure this out.

    Try this:

    {
        "data": "prov_destinatario"
    },
    {
        "data": "tratta",
    render: function ( data, type, row ) {
                if ( row.prov_destinatario == "SA"  ) {
                    return 'Campania';
                }
                if (row.prov_destinatario == "TE") {
                    return 'Adriatico';
                }
                return data;
        },
    className: "dt-body-center",
     
    }
    

    You also need to make sure you return something in case neither of the two conditions is being met. In that case you return "data" which is the same as "row.tratta".

  • antoniocibantoniocib Posts: 277Questions: 62Answers: 1

    Thanks @rf1234 but i solved with a Left Join!!
    Thanks for the support

Sign In or Register to comment.