How to add record ID to the link in my edit buttons

How to add record ID to the link in my edit buttons

KristianKristian Posts: 7Questions: 2Answers: 0

Hi all,

I have a list of users and in the last column I have an edit button, defined using columnDefs.

https://jsfiddle.net/kharmer/Lf5vxm8d/

How do I got about assigning the record ID to each edit button on each row? The documentation has confused me a little!

Best regards,
Kris...

Answers

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

    You would use columns.render for that. It'll give you more control that defaultContent that you are currently using,

    Colin

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Here is an example using columns.render. It uses the meta parameter to get the row index for the button ID.
    http://live.datatables.net/qemodapi/1/edit

    Kevin

  • KristianKristian Posts: 7Questions: 2Answers: 0

    Thanks guys - thanks for the example.

    I have it working using an onclick method; however I wondered if there was a more elegant way to build the URL with the clientID during render of the column button?

    Kris...

  • KristianKristian Posts: 7Questions: 2Answers: 0

    ...would taking the value from a hidden column be the best way to go instead of a data-userID attribute on the TR element?

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

    Either way would work, I wouldn't say one is better than the other,

    Colin

  • KristianKristian Posts: 7Questions: 2Answers: 0
    edited July 2020

    Oddly, every way I have seen to hide a column doesn't seem to work for me! Unless I use a Bootstrap class="d-none" on the TH and TD...

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

    Could you link to a test case demonstrating that, please?

    Colin

  • KristianKristian Posts: 7Questions: 2Answers: 0
    edited July 2020

    Hi Colin,

    Thanks - I managed to find a way round this by adding a Bootstrap presentation class of 'd-none' to the relevant columns TH and TD tag and then remove it from the colVis toggle menu using the 'noVis' class. So more through CSS classes rather than programatically.

    My code is more or less the same as the example in my initial post, accept I am now using columnDefs render instead of columnDefs defaultContent to add my row buttons.

    Still, the following never seemed to take affect.

            {
                targets: [ 3 ],
                visible: false
            }
    

    Thanks,
    kris...

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Still, the following never seemed to take affect.

    Its hard to say with just that small code snippet. Can you update your example to show the issue? Maybe its being overwritten by another column or columnDefs option??

    Kevin

This discussion has been closed.