Add a increment for Add and Remove Buttons

Add a increment for Add and Remove Buttons

rdbrdb Posts: 9Questions: 2Answers: 0

I am looking to Add an incremented number to my Add and Remove buttons. So AddBtn_0 is this possible to do with Data Tables? Here is my Code:

https://jsfiddle.net/vo5yfnd4/

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I'm afraid I don't quite understand. Are you able to mock up a screenshot?

    Thanks,
    Allan

  • rdbrdb Posts: 9Questions: 2Answers: 0

    Similar to how I have this on a button:

    <a href="/ArtistAccount/TES0000000001A/SongManagement/TES0000000005S/Recordings" **id="recordingWork_0**">Recordings</a>

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Oh I see - you just want to add an id to the button? Use buttons().nodes() and loop over the button elements, adding the ids you want.

    Allan

  • rdbrdb Posts: 9Questions: 2Answers: 0

    Hi Allan,

    Thanks for the recommendation, do you know how I could do it with my code, as its a little different.

  • rdbrdb Posts: 9Questions: 2Answers: 0

    Hi Allan,

    Do you know if I could do it using: https://datatables.net/examples/server_side/ids.html

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Sounds like you are asking about the buttons you are adding to each row but Allan is talking about buttons added using the Buttons extension.

    I'm not sure but I think the syntax you have is incorrect. Maybe this example will help:
    http://live.datatables.net/qemodapi/1/edit

    Kevin

  • rdbrdb Posts: 9Questions: 2Answers: 0

    Hi Kevin,

    Right okay. i will have a look at that, I was not sure if there was something that I could already use within DataTables. It works to a points, its just each time the table is re-drawn when it adds or removes the count is not reset.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    It works to a points, its just each time the table is re-drawn when it adds or removes the count is not reset.

    I'm not sure what counts you are talking about. Maybe you can provide a link to your page or a test case showing the issues.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • rdbrdb Posts: 9Questions: 2Answers: 0

    Hi Kevin,

    It's not public facing so I can't show you, I can only show you the code I currently have. In the past, I have added id's to each button using pagination, so that when it loads the data into the data table say you have 50 results it paginates the number of results. but when it loads the table with the add buttons it would have AddBtn and then as the id have _0 for the first record in the table.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    Maybe you can update my test case with your code?

    Maybe you saw this but if you look at the columns.render docs the meta.row that I use in the example is the row index. Is that what you are looking for?

    Kevin

  • rdbrdb Posts: 9Questions: 2Answers: 0

    Hi Kevin,

    There is a JSFiddle in my original question.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    Yes there isa fiddle in the first post but it doesn't appear to run and there is a lot of code. I see this in the fiddle:

                        {
                            data: null,
                            targets: [6],
                            sClass: "updateTableRow text-center",
                            render: function ( data, type, full, meta )
                            {
                                var id = data["ID"];
                                return `<button class=\"btn btn-danger br2 btn-xs fs12 table-btn button-selector-${id}\" id=\"RemoveContractBtn\">Remove</button>`;
                            }
                        }
    

    Is this the button you want to increment the id? Can you use the data["ID'] value for the ID if the row index is not good?

    Maybe it would help to understand what you are doing with the row id. Is it sent to the server and needs to be something specific?

    Kevin

  • rdbrdb Posts: 9Questions: 2Answers: 0

    Hi Kevin,

    meta.rowseems to have worked.

    Thanks

This discussion has been closed.