change css of filtered rows in datatable

change css of filtered rows in datatable

chrysalischrysalis Posts: 9Questions: 0Answers: 0
edited March 2011 in General
i am using $.fn.afnFiltering.push(...) to filter rows in my table based on a certain daterange....i cannot figure out how to address individual rows inside this function....
heres my code...

[code]$.fn.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
var iFini = document.getElementById('dateStart').value;
var iFfin = document.getElementById('dateEnd').value;
if (iFini == "" && iFfin == "") {
return true;
}
else if (iFini != "" && iFfin == "") {
return true;
}
else if (iFini == "" && iFfin != "") {
return true;
}
else if (iFini != "" && iFfin != "") {
var sdate = new Date();
var edate = new Date();
var initialdt = iFini.split("/");
var enddt = iFfin.split("/");
var filterdt1 = aData[3].split(" ");
var filterdt = filterdt1[0].split("/");
var msg = "";
if ((Number.parseInvariant(filterdt[0]) + 1 >= Number.parseInvariant(initialdt[0]) + 1 && Number.parseInvariant(filterdt[0]) + 1 <= Number.parseInvariant(enddt[0]) + 1) && (Number.parseInvariant(filterdt[1]) >= Number.parseInvariant(initialdt[1]) && Number.parseInvariant(filterdt[1]) <= Number.parseInvariant(enddt[1])) && (Number.parseInvariant(filterdt[2]) >= Number.parseInvariant(initialdt[2]) && Number.parseInvariant(filterdt[2]) <= Number.parseInvariant(enddt[2]))) {
// msg = "initialdt: " + initialdt[0] + "/" + initialdt[1] + "/" + initialdt[2] + "====" + "enddt: " + enddt[0] + "/" + enddt[1] + "/" + enddt[2] + "====Filter:" + filterdt[0] + "/" + filterdt[1] + "/" + filterdt[2] + "/n"
//$(this).push();
return true;
}

}

return true;
}
);[/code]

thanks

Replies

  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    reason why i am returning true at the end is because i want the filter to return all rows and highlight only the ones that were filtered...
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Your function is called once for every row in the table, and aData in the function contains an array with one element for each column in that row.

    It's a nice idea highlighting the rows which match your search - I like that :-). So I guess you want the TR element? For that what you can do is: oSettings.aoData[ iDataIndex ].nTr . It's an internal reference to the row, so you can add / remove a class as needed.

    Allan
  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    thanks allan...i got it to work but only partially...on the initial load the function only highlights rows on the first page....what i am seeing is that only pages that are actually 'loaded'...so if i just loaded and then filtered the data it would just apply the coloring to the first page only...then when i click next and go to the second page and filter again it works....but not with the 3rd page...

    is there something i am missing????
    thanks for the help...
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Are you using server-side processing? With server-side processing enabled the filtering is done entirely on the server-side, and I'm not 100% sure what would happen with custom filtering at the moment. The function should be called exactly once on every filter for every row that DataTables knows about.

    Allan
  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    i am using an asp.net control called a repeater to bind the data and using your grid control to display it....once the data is bound there are no more server calls for filtering or searching...its all on the client side....
    is there any way i can call fnDraw() when the next or one of the paging buttons is clicked such that it updates that page and runs my filter alongwith it....
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    fnDraw is called automatically when the page is redrawn - you would head into an infinite loop otherwise :-). I'd suggest adding a little debug into your filtering function and make sure it is being called once for every row in the table, not just the ones on display.

    Allan
  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    ok i changed my approach a bit...
    i am using fnGetNodes() to get all the nodes in the datatable....and then iterating over each row and adding a class to it but still no luck...only the rows in the current view get updated...why is that happening...
    thanks
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    I'm not certain I'm afraid. Can you give us a link to your page so I can see it in action please?

    Allan
  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    allan,
    this is not public yet so i wont be able to connect you with the site....in the meantime heres another problem...if my data table has a significant amount of rows...afnfiltering.push causes a too much recursion error on the client....any way to get around this...
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    There is quite a lot going on in your filtering function - ideally you want it to operate as quickly as possible. You almost certainly don't want to be doing DOM gets on each call to it. I'd start by caching your getElementById results and otherwise looking for ways to speed up the function.

    Allan
  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    i have found ways to make this work.....i just have one question...is there any internal field that stores the number of pages in a datatable....
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    No - it needs to be calculated if you want that information. oSettings.fnRecordsDisplay() / oSettings._iDisplayLength.

    Allan
  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    i have a couple of date columns that are also showing time components that i dont need....how do i get rid of the timestamp
  • chrysalischrysalis Posts: 9Questions: 0Answers: 0
    allan,
    i am using bvisible=false for some columns but need to still get the values from the columns for a db call....how do i get those values from the hidden columns....currently i am getting nulls....
    this is how i am trying to get the values

    var CaseChapter = $(this).find("td:nth-child(5)").text();
    var CaseLink = $(this).find("td:nth-child(6)").text();

    case link is hidden and doesnt get a value...while chapter is visible and gets the value...
    thanks
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    fnGetData ( http://datatables.net/api#fnGetData ) will get you the full data for the row, regardless of the column visibility. Just pass it the row node you want the data for.

    Allan
This discussion has been closed.