Any way to insert anchor elements into the table dom?

Any way to insert anchor elements into the table dom?

BlueHuesBlueHues Posts: 16Questions: 5Answers: 0

I'm not particularly well acquainted with doms and i'm wondering if I can somehow insert anchor elements and/or simple text into the table dom, just how, say, the buttons are inserted in a 'Bfrt' dom

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    If you mean "How to insert a link in a table td element", there's an example here:
    https://datatables.net/reference/option/columns.render

  • BlueHuesBlueHues Posts: 16Questions: 5Answers: 0
    edited March 2023

    Not quite. I'm simply (hopefully) trying to use the table DOM, so I could line up both the filter input that the datatables provide via dom and my own anchor elements into one line, so it would look more pleasing.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓
  • BlueHuesBlueHues Posts: 16Questions: 5Answers: 0

    Yes, that's exactly it! Thank you!

  • BlueHuesBlueHues Posts: 16Questions: 5Answers: 0

    After quite a bit of testing, i cant seem to be able to insert an actual, working anchor element, as it becomes simple unclickable text. Am I missing something?

    Here's the code:

    The dom

    dom: "<'row'  <'col-sm-12 col-md-6'<'linkA'>>  <'col-sm-12 col-md-6'f>  >" +
                        "<'row'  <'col-sm-12'tr>  >",
    

    The "linkA" element:

    $('div.linkA').html('<a asp-action="ActionA" asp-route-page="statusIndex">+New</a>');
    

    The output (doesn't work as a link, obviously):

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Adding an href attribute to your code provides a clickable link:
    https://live.datatables.net/xovatefi/1/edit

    I'm not familiar with ASP.NET but the asp-action doc seems to indicate that the above CSHTML will be converted to something like this:

    <a href="ActionA">+New</a>
    

    Not sure what the asp-route-page would convert to.

    Kevin

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    It depends how the -asp-action attribute works. Does ASP need something to run for that to be picked up? I don't know I'm afraid - you'd need to ask in an ASP forum or perhaps StackOverflow.

    Allan

  • BlueHuesBlueHues Posts: 16Questions: 5Answers: 0

    Hi! thanks for the inputs so far. You can think of the asp-route-page as a variable that is passed to the ActionA method, so i dont think it'll cause me too much trouble.

  • BlueHuesBlueHues Posts: 16Questions: 5Answers: 0

    I've changed The link as per Kevins suggestion, and it works just fine now. Once again, thanks for the extensive help.

Sign In or Register to comment.