0

May be this question is asked before but i am stuck in a position where i am able to sort my data table at the time of page loading.But when i replace the whole table with data populated by ajax then it stops working.Please help me.

i am using the following code according to jQuery table sort

$('#loc_sort, #rate_sort')  // these are the th ids that i want to sort
.wrapInner('<span title="sort this column"/>')
.each(function(){       
    var th = $(this),
        thIndex = th.index(),
        inverse = false;

    th.click(function(){

        table.find('td').filter(function(){

            return $(this).index() === thIndex;

        }).sortElements(function(a, b){

            return $.text([a]) > $.text([b]) ?
                inverse ? -1 : 1
                : inverse ? 1 : -1;

        }, function(){

            // parentNode is the element we want to move
            return this.parentNode; 

        });

        inverse = !inverse;

    });

});

please tell me how can i use this code with .on method.I append the html code that coming from ajax to

<div id="outer_all_div"></div>

div.Which is not replacing.Please help me.Thanks in advance.

Community
  • 1
  • 1
ABorty
  • 2,512
  • 1
  • 13
  • 16

1 Answers1

1

Simply bind your event to the parent. Then it only needs to be bound once and it won't get lost when you replace the inner table.

$('#outer_all_div').on('click', '#loc_sort, #rate_sort', function() {
    ...
});
Matt S
  • 14,976
  • 6
  • 57
  • 76