onLoad function overwritten

onLoad function overwritten

kalusnkalusn Posts: 3Questions: 0Answers: 0
edited November 2010 in General
Hey guys, first time poster here, so I'll try to be precise.

I have a table which is being generated server-side. I also, in each row, have a "remove" or "add" link, which removes or adds an element from its group via. ajax.

My problem is this: It works as it should, right up until I use dataTable to search, paginate or sort. Then the ajax functionality I've defined on my links stops working, and the links go back to their JS-disabled behaviour. It's like every time dataTables is refreshed, it overrides the jQuery onload function $(function() { });

I can give example code if you need to see the problem clearer.

Replies

  • kalusnkalusn Posts: 3Questions: 0Answers: 0
    Okay this is weird.

    Before my code was like this:
    [code]
    $(function(){

    $("#quotes_table").dataTable({
    "sPaginationType": "full_numbers"
    });

    $(".plus").click(function(e){
    var plus = $(this);
    $.ajax({
    url: this.href,
    type: 'post',
    dataType: 'script',
    data: { '_method': 'create' },
    success: function(){
    plus.html(' ');
    }
    });
    return false;
    });

    $(".minus").click(function(e){
    var minus = $(this)
    $.ajax({
    url: this.href,
    type: 'post',
    dataType: 'script',
    data: { '_method': 'delete' },
    success: function(){
    minus.html(' ');
    }
    });
    return false;
    });

    });
    [/code]
    But moving [code]
    $("#quotes_table").dataTable({
    "sPaginationType": "full_numbers"
    });[/code]
    to the end of the onLoad function solves the problem.

    Can anyone explain this to me?
  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    Certainly :-) This FAQ addresses this point: http://datatables.net/faqs#events

    Allan
  • kalusnkalusn Posts: 3Questions: 0Answers: 0
    Thanks allan. I feel a bit ashamed it's so high up on the FAQ list and I didn't notice it :). Sorry about that.
  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    No worries. One of those things - easy when you know how!

    Allan
This discussion has been closed.