Combine render "[, ].name" & render: editIcon together?

Combine render "[, ].name" & render: editIcon together?

willis30willis30 Posts: 5Questions: 1Answers: 0
edited November 2021 in General

How do I use render "[, ].name" as well as the render: editIcon together?

I've got everything working with my mjoin and pulling in the names seperated however I want to be able to edit it inline like the example Edit Icon. I've got it working on my other fields but not having any luck with the comma seperated.

Hope that makes since

This question has an accepted answers - jump to answer

Answers

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

    Are you able to link to your page so we can take a look, please. Or if not, please can you post your table initialisation code and a snippet of the data you want rendered.

    Colin

  • willis30willis30 Posts: 5Questions: 1Answers: 0

    var table = $('#trac').DataTable( {
    responsive: true,
    dom: 'Bfrtip',
    ajax: {
    url: 'trac.php',
    type: 'POST'
    },
    serverSide: true,
    order: [[ 1, 'asc' ]],
    columns: [
    { // Responsive control column
    data: null,
    defaultContent: '',
    className: 'control',
    orderable: false
    },
    { data: "trac_title", render: editIcon },
    { data: "types.type_name", render: editIcon },
    { data: "vendors.company", render: editIcon },
    { data: "users", render: "[, ].users_name"},
    { data: "server", render: editIcon },
    { data: "system_name", render: editIcon },
    { data: "start_date", render: editIcon },
    { data: "end_date", render: editIcon }
    ],
    select: true,
    buttons: [
    { extend: "create", editor: editor },
    { extend: "edit", editor: editor },
    { extend: "remove", editor: editor }
    ]
    } );

    The Contact Users Column I can't get it to have the names comma separated as well as the edit inline icon.

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

    Can you also post a couple of lines of the data as it's returned by the server, please,

    Colin

  • willis30willis30 Posts: 5Questions: 1Answers: 0

    Like so?

    trac: {trac_title: "Testing", server: "this one",
    start_date: "2021-11-04",
    end_date: "2021-11-04",…}
    trac_systems: {system_name: "Test System2"}
    trac_types: {type_name: "Certificate"}
    trac_users: [{user_id: "1234567", users_name: "Chris Brown"},…]
    0: {user_id: "1234567", users_name: "Chris Brown"}
    1: {user_id: "9876543", users_name: "Colt Williams"}
    trac_vendors: {company: "Vendor Name"}

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

    I reformatted it here, but it looks like there are a few errors such as missing commas between the elements. Could you just verify that they are present in the posted data - this was truncated, as you can tell by the ellipses in your post.

    [
       {
          "trac":{
             "trac_title":"Testing",
             "server":"this one",
             "start_date":"2021-11-04",
             "end_date":"2021-11-04"
          },
          "trac_systems":{
             "system_name":"Test System2"
          },
          "trac_types":{
             "type_name":"Certificate"
          },
          "trac_users":[
             {
                "user_id":"1234567",
                "users_name":"Chris Brown"
             }
          ],
          "0":{
             "user_id":"1234567",
             "users_name":"Chris Brown"
          },
          "1":{
             "user_id":"9876543",
             "users_name":"Colt Williams"
          },
          "trac_vendors":{
             "company":"Vendor Name"
          }
       ]
    
  • willis30willis30 Posts: 5Questions: 1Answers: 0
    edited November 2021

    Sorry I didn't notice that when I pasted it in after cleaning it up it appears that what I have matches your post

        `[
            {
                trac":{
                    "trac_title":"Testing",
                    "server":"this one",
                    "start_date":"2021-11-04",
                    "end_date":"2021-11-04"
                },
                "trac_types":{
                    "type_name":"Certificate"
                },
                "trac_vendors":{
                        "company":"Vendor Name"
                        },
                "trac_systems":{
                        "system_name":"Test System2"
                        },
                "trac_users":[
                    {
                        "user_id":"1234567",
                        "users_name":"Chris Brown"
                    },
                    {
                        "user_id":"9876543",
                        "users_name":"Colt Williams"
                    }
                ]
            }
        ]`
    
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Answer ✓

    How do I use render "[, ].name" as well as the render: editIcon together?

    You don't I'm afraid - you can have only one render function. You would need to create a function to do that. However for this specific case, you could use:

    {
      data: "users[, ].users_name",
      render: editIcon
    },
    

    The columns.data property can use the array syntax as well.

    Allan

  • willis30willis30 Posts: 5Questions: 1Answers: 0

    Perfect, I knew it had to be something simple.
    Thanks Allan!

Sign In or Register to comment.