noob question - jquery code that ran for every row not working after I "datatable" my table
noob question - jquery code that ran for every row not working after I "datatable" my table
I have some jquery code that iterates through all my table rows and dynamically sets and image src based on the data in the row (code shown below). That function works well until I converted my table to a datatable - now the images are created only for the 10 initially visible rows in the database.
I can easily fix the problem by making my datatable() call after the image processing function, I was wondering instead if there was an event that fired as a row became visible - I could also call the image-setting code there. (although I would not want to call it more than once).
thanks in advance.
[code]
$(".imgOnBase").each(function () {
var $obj = $(this);
var src = '@Url.Content("~/Content/images/bases")';
src += $obj.siblings(".hidOnBase").val();
src += '.bmp'
$(this).attr('src', src);
});
[/code]
I can easily fix the problem by making my datatable() call after the image processing function, I was wondering instead if there was an event that fired as a row became visible - I could also call the image-setting code there. (although I would not want to call it more than once).
thanks in advance.
[code]
$(".imgOnBase").each(function () {
var $obj = $(this);
var src = '@Url.Content("~/Content/images/bases")';
src += $obj.siblings(".hidOnBase").val();
src += '.bmp'
$(this).attr('src', src);
});
[/code]
This discussion has been closed.
Replies
Alternatively, in DataTables 1.9 what you are able to do is:
[code]
table.$(".imgOnBase").each(function { ....
[/code]
where 'table' is the DataTables instance.
Allan