TR Attribute On New Rows

TR Attribute On New Rows

jLinuxjLinux Posts: 981Questions: 73Answers: 75

I need to add some new attribute tags to the <tr> tag for any new table rows that are created, I thought it was using the fnRowCallback, but it doesnt seem to be working at all... Can someone tell me wha tim doing wrong?

var t = $attributes_table.dataTable({
            "bPaginate": false,
            "bFilter": false,
            "bSort": false,
            "fnRowCallback": function ( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                $( nRow ).prop('id', aData.RowOrder);
                $( nRow ).prop('TEST123123123', aData.RowOrder);
            }
        });

I would expect the id and TEST123123123 to show up with some values

This question has an accepted answers - jump to answer

Answers

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16
    edited July 2015 Answer ✓

    Hi jhyland87,

    if you are retrieving the data server-side you can add and fill data table specific properties that will get picked up when the rows are rendered. You can look for an example here: Automatic addition of row ID attributes.

    If however you wish to achieve this purely on the client side you can use createdRow call-back.

    Example:

    $('#example').dataTable( {
      "createdRow": function( row, data, dataIndex ) {
           $(row).attr('id', data.RowOrder);
           $(row).attr('TEST123123123', data.RowOrder);
      }
    } );
    

    Hope this helps,

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Oh wow, that fixed a few of my other issues too, thanks!

    Is there no difference between fnCreatedRow and CreatedRow?

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16
    edited July 2015

    The difference is the version of DataTables, the example I provided uses the new 1.10.x API reference.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    @Ashbjorn - You answer a ton of questions overnight - thank you :-)

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    You both do! Thanks guys

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16
    edited July 2015

    @allan - just my appreciation for such an excellent plugin, and your backlog isn't getting any smaller either, I wonder if the old questions will ever get an answer, they might be irrelevant by now even.

    Never hurts to help, my clients are always happy with the DataTable implementations I write so it never hurts to pay it forward! (Which reminds me I am overdue on my supporter purchase, should be on its way Allan!)

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Unfortunately I suspect a number of forum questions will inevitably go unanswered forever now. More than 28'000 threads in this forum with ~30 new threads and ~80 comments being added per day. It would almost be a fully time job to just answer questions and that wouldn't drive the software forward...

    Allan

  • AshbjornAshbjorn Posts: 55Questions: 2Answers: 16

    Perhaps just purge (lock) questions before a certain version was released? Since you will probably want to focus on 1.10.x anyway?

    You could then let the questions expire naturally over time, 6 months no reply? The user is probably not waiting for an answer anymore either? Instead of having 3700 unanswered questions you might be able to drop to a more relevant number by closing/locking very old ones.

    Not sure how the backing forum software handles this but a cleanup might be in order now that DataTables has evolved so much after 1.10.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    I lock old discussions. At the moment anything before 2015-04-01 will be locked. So it is by date rather than by version. I do fancy the idea of adding a version option to the "create new discussion" form which might allow that in future.

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    I try to help by spreading the word! lol. I definitely use it enough. Im working on an app that were kinda on the line if it should be Open Source or if we should sell it, if we sell it, we will pay for the paid version for sure!

This discussion has been closed.