how to render an array in a column

how to render an array in a column

ehardingeharding Posts: 13Questions: 6Answers: 0

I have a checkbox field

{
                label: "Contact Name: *",
                name: "apd_history.agency_contact",
                type: "checkbox",
            },

{ data: "apd_history.agency_contact", render: "[, ]agency_contact" },

the field works,and the data (i.e. multiple values separate by commas are inserted into the db) but I can't figure out how to get the contents of that column to render on the table. I don't need/want to edit it. I just want to display the cont

Replies

  • allanallan Posts: 61,637Questions: 1Answers: 10,092 Site admin

    The columns.data and columns.render properties work together. Basically whatever the data property points to the render will see as the data for the column. So I think in the above you probably want to use:

    {
      data: "apd_history",
      render: "[, ]agency_contact"
    },
    

    Or perhaps:

    {
      data: null,
      render: "apd_history[, ]agency_contact"
    },
    

    Using data: null will let the renderer see the whole original object.

    Allan

  • ehardingeharding Posts: 13Questions: 6Answers: 0
    edited February 2017

    thanks, but neither seemed to help, started getting http://datatables.net/tn/4.

    The json contains the id in the column, but they are generating the names "agency_contact":"2591,1311"

    {
        "data": [{
            "DT_RowId": "row_90",
            "apd_history": {
                "apd_num": "201",
                "history_date": "2017-02-23",
                "history_type_code": "Phone Call",
                "author_name": "eharding",
                "agency_contact": "2591,1311",
                "history_title": "test",
                "meeting_purpose": "",
                "meeting_process": "",
                "meeting_payoff": "",
                "agency_code": "10910"
            },
            "apd_users": {
                "full_name": "Eric Harding"
            }
        }]
    }
    
  • allanallan Posts: 61,637Questions: 1Answers: 10,092 Site admin

    Oh I see - thanks. You don't have an array in the apd_history property. Its an object.

    So you would use apd_history.agency_contact.

    The [] syntax is used to get data from an array.

    Allan

  • ehardingeharding Posts: 13Questions: 6Answers: 0

    thanks, that and adding separator "," did it!

This discussion has been closed.