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

tagliustaglius Posts: 1Questions: 0Answers: 0
edited January 2012 in General
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]

Replies

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    You need to use fnGetNodes to get all TR nodes.

    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
This discussion has been closed.