3

I'm trying to create a row inside my datatable that increments +1 each row. I've been told the easiest way to do this would be using fnRender. Now I've used fnRender to change data that's already in a column from the serverside processor, but never to create a new column alone.
Any help would be awesome!

Here's my current code:

oTable = $('#testingz').dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "aaSorting": [ [1,'desc'] ],
    "sDom": '<""l>rt<"F"fp>',
        "sAjaxSource": "server_processing.php",
        "aoColumnDefs": [ 
            {
                "fnRender": function ( o, val ) {
                return '<a href="http://honedge.com/' + o.aData[0] + '">' + o.aData[0] + '</a>';
                },
                "aTargets": [ 0 ]
            }
        ]
});
1
  • not 100% sure what you are asking. Would adding var ctr=0; above oTable and then ctr++ inside fnRender not do what you need? Commented Jun 16, 2012 at 0:32

1 Answer 1

1

Do you mean something like this: http://datatables.net/release-datatables/examples/api/counter_column.html

Sign up to request clarification or add additional context in comments.

3 Comments

Essentially this is what I need, I just need the numbers to stay "attached" to a certain row regardless of sorting and searching. It's used to give a rank to a player when it's initially grabbed from the database, so the first person would be rank 1. In that example, no matter the case, the first row is always indexed as 1. Say the 35th person has an index of 35. If i were to search for that player with a username, his index would read 1. I need it to read 35 no matter what :P
In which case, rather than using fnDrawCallback as my example does - just loop over the data updating it with the column index once at initialisation time.
Sounds exactly like what I want to do- i just have no clue how to... Silly me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.