I am using the JQuery DataTables plugin for displaying large sets of data. One thing I am trying to do is shorten the 'details' column (sometimes they are around 1000 characters) to a small string so that the rows are all fairly the same height and easier t开发者_如何学Pythono read. Then when a user clicks on the small string, it opens a dialog and displays the full details.
It works great, but only on the first 10 rows (since those are all that is shown by default). Once I expand the table to display the rest of the rows, the function doesnt seem to be applied to those newly shown rows. Is there a call or option in dataTables that will apply the function everytime the row set being shown is changed?
Here is the dataTables call:
$('#dataTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"fnInitComplete": function(){
$('.display_results').show();
$('.def').click(function(){
var msg = $(this).next().text();
$('.messages').messageBox();//Custom Dialog box call
});
}
});
Figured it out! http://datatables.net/usage/callbacks use 'fnDrawCallback'
$('#dataTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"fnInitComplete": function(){
$('.display_results').show();
},
"fnDrawCallback": function() {
$('.def').click(function(){
var msg = $(this).next().text();
$('.messages').messageBox()//Custom Dialog
});
}
})
I guess you could use "fnDrawCallback" property while declaring the "DataTable" as we have used in our recent project.
Its best to use live events for this kind of thing: http://datatables.net/faqs#events . Ideally the messageBox plug-in could be modified to use live events.
Allan
Actually what you should had done is:
$(".def").live('click', function() {
//your code here
});
精彩评论