Replace Value in Column with Value from Array

Replace Value in Column with Value from Array

AirprimusAirprimus Posts: 10Questions: 5Answers: 0

Hello,

I need some food for thought. I have a column with the ID of a supplier. I have the suppliers in an array, up to now I always retrieved this by $lieferant_array[$lieferantId]->value;. How can I implement this in the editor? Because the column now shows the ID and not the name from the array.

I hope I have expressed myself clearly.

Here is the link to the debug: https://debug.datatables.net/iqikad

Thanks

Lars

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416

    Lars,

    your link is a 404 ...

    Roland

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Ah it's not a 404, it's just visible to the site administrators. We'll take a look and report back,

    Colin

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    I should really change that 404 to a 401... Thanks for pointing that out.

    @Airprimus - You have:

            "s_articles_supplier": {
                "name": "H\u00f6rmann"
            },
    

    in your JSON. Is that what you want to show in the column? If so use columns.data with data: 's_articles_supplier.name'.

    Allan

  • AirprimusAirprimus Posts: 10Questions: 5Answers: 0

    Hello, Allan,

    no, I mean the column s_articles_attributes.supplier. In this column the supplier ID is loaded from the database. The supplier's ID is not in the database but in an array. The array looks like this:

    [{"key":"0","value":" "},{"key":"1","value":"H\u00f6rmann KG"},{"key":"2","value":"GEZE GmbH"},{"key":"3","value":"GEZE Service GmbH"},{"key":"4","value":"Assa Abloy"},{"key":"5","value":"Bircher"},{"key":"6","value":"Dictator"},{"key":"7","value":"dormakaba"},{"key":"8","value":"GfA"},{"key":"9","value":"Hekatron"},{"key":"10","value":"ELKA"},{"key":"11","value":"Marantec"},{"key":"12","value":"CAME"},{"key":"13","value":"Belfox"},{"key":"14","value":"Planet"},{"key":"15","value":"Locinox"},{"key":"16","value":"FAAC"},{"key":"17","value":"Werma"},{"key":"18","value":"BEA"},{"key":"19","value":"Marx"},{"key":"20","value":"Meesenburg"},{"key":"21","value":"WSS"},{"key":"22","value":"esco"},{"key":"23","value":"CTM Berlin"},{"key":"24","value":"Datelsoft"},{"key":"25","value":"D-Secour"},{"key":"26","value":"Safepart"},{"key":"27","value":"Bft"},{"key":"28","value":"Sperling"},{"key":"29","value":"STF"},{"key":"30","value":"Sonepar"},{"key":"31","value":"Zander"}]

    I would now like to display the name from the array in the column supplier instead of the ID. Unfortunately I have no idea how to implement this with the Datatables.

    Thanks

    Lars

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Hi Lars,

    You would use a renderer. For example you might use:

    {
      data: 'id_of_supplier', // change to whatever the JSON data point is
      render: function (data, type, row) {
        let match = suppliers.find( s => s.key == id );
        return match
          ? match.value
          : 'Unknown supplier';
      }
    }
    

    Assuming your array of suppliers is called suppliers - change as required.

    Allan

This discussion has been closed.