fnDisplayRow with url hash

fnDisplayRow with url hash

Forsti83Forsti83 Posts: 5Questions: 0Answers: 0
edited July 2009 in Plug-ins
Hello!

I use the url hash in my application to scroll to a certain row on my page. With the usage of DataTables this isn't possible, the first page is always shown. Now I want to use fnDisplayRow to show the right page of the table.

I want to do something like that, but I can't get it to work:

[code]
var hash = window.location.hash;
var test = $(hash);
oTable.fnDisplayRow(oTable.fnGetNodes()[oTable.fnGetPosition(test)]);
[/code]

Any suggestions?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hello,

    Have you included the plug-in API function fnDisplayRow() correctly? Does "oTable.fnGetNodes()[oTable.fnGetPosition(test)]" correctly resolve to what you expect it to (i.e. an integer)?

    Allan
  • Forsti83Forsti83 Posts: 5Questions: 0Answers: 0
    edited July 2009
    Hello,

    I included the fnDisplayRow function in the $(document).ready(function() {} block... With something like
    [code]var node = oTable.fnGetNodes()[123][/code]
    I get the node, but when I call
    [code]oTable.fnDisplayRow(node)[/code]
    nothing happens...

    Andi
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    HI Andi,

    Okay, first thing is a sanity check - I presume that the node '123' hasn't actually already been put on the first page by sorting or something? Next, are you getting any Javascript error messages showing up in the Firebug / Web Inspector / whatever console? Where did you include the code for fnDisplayRow()? And finally - do you have a link? That might this much easier!

    Regards,
    Allan
  • Forsti83Forsti83 Posts: 5Questions: 0Answers: 0
    Hi Allan,

    the selected node is not already on the first page and I don't get any error messages in the Firebug console. Here is a link to my example code: http://www.forstmayr.de/test/test.php

    I put my plugin functions like fnDisplayRow() in a file called jquery.dataTables.custom.js.

    Thank you so much!

    Andi
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hi Andi,

    I think I've got it - the plug-in function appears to assuming DataTables 1.5 (currently in beta) where as you are currently using DataTables 1.4 - I should really have noted that in the code - sorry. So two options:

    1. Make the plug-in compatible with 1.4, which I think is simply a case of changing "_iDisplayStart" and "_iDisplayLength" for "iDisplayStart" and "iDisplayLength" respectively (although haven't checked that!)

    2. Use DataTables 1.5 beta 10 (or newer if available at the time!). It should be completely backwards compatible with 1.4.

    Btw - very nice styling of DataTables! I have to view source just to check that it was DataTables - love it! Perhaps when your project is complete you could add a link or screenshot to the 'How do you use' thread?

    Regards,
    Allan
  • Forsti83Forsti83 Posts: 5Questions: 0Answers: 0
    Hi Allan,

    thank you so much for your help and your brilliant project DataTables!! Option #1 finally worked for me.

    When the project is complete I will add a link to the thread.

    Regards,
    Andi
  • Forsti83Forsti83 Posts: 5Questions: 0Answers: 0
    Hi Allan,

    I still have another question: The fnGetPosition function only works for me if the row is visible on the current page. How do I get the position of a row on another page?

    Regards,
    Andi
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hi Andi,

    fnGetPosition() operates on the whole set of data (unless you are using server-side processing of course, since it only knows about the current page). If you have a look at the code you'll see it uses oSettings.aoData.length - which is all data - so there shouldn't be anything restricting it to the current page - assuming that you are passing a TR or TD element which is in the table.

    Allan
This discussion has been closed.