fnLengthChange() changes the value of all my select fields

fnLengthChange() changes the value of all my select fields

SamMSamM Posts: 2Questions: 0Answers: 0
edited March 2011 in Plug-ins
Hi,

First of all, I would like to thank you for this lovely piece of coding. I'm using the code in my project at school after I was getting sick of the problems with tablesorter. This piece of code is soo much better, you rock dude.

Back to my question:
I am using the fnLengthChange plugin from your page. It works very well except that when I call the function, it will change the values in all of my select fields. I'm rather new to jQuery so I'm not really into the debugging of these big coding projects yet.

As far as I managed to trace it, the error is in this line:
[code]
$('select', oSettings.oFeatures.l).val( iDisplay );
[/code]
If I place this line in comment, then I do not have the error on my webpage. But I'm not able to trace this any further because I do not now how jQuery handles this selector with a comma and a variable. I've also checked the value of "oSettings.oFeatures.l" and it is undefined. I did a search in your jQuery file for "oFeatures.l" but couldn't find it. So I think that this plugin has a small bug there.

Could you please help me to solve this.

I hope my explanation is clear. If not, please tell my what other information you need.

Kind regards

Replies

  • SamMSamM Posts: 2Questions: 0Answers: 0
    Is there anyone who knows a solution to this.

    Thank you very much.
  • espringerespringer Posts: 2Questions: 0Answers: 0
    The same thing was occurring in my code: all the select dropdowns were having their selected values cleared out by this line of code. The solution was to change the line above to specifically call the select dropdown in question (the dropdown containing the number of results to show.)

    First you need the ID of the div that contains your datatable. I used the Firefox Firebug plugin to find the div being populated. In my code:






    Heading 1
    Heading 2








    And then I added that same value from the ID attribute to my fnLengthChange code:

    $('#MyDataTable select', oSettings.oFeatures.l).val(iDisplay);

    That will ONLY change the selects within the datatable, not all the selects on the page!

    That should work for you. If your datatable div doesn't have an id, just add one.
  • mmatyasmmatyas Posts: 5Questions: 0Answers: 0
    In fnLengthChange change:

    [code]$('select', oSettings.oFeatures.l).val( iDisplay ); [/code]

    to:

    [code]$('select', oSettings.aanFeatures.l).val( iDisplay ); [/code]
  • mmatyasmmatyas Posts: 5Questions: 0Answers: 0
    Can we get the plugins page updated?
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Now done - thanks very much for flagging that up!!

    Allan
  • mihajlomihajlo Posts: 2Questions: 0Answers: 0
    I had some problems with this plugin when using custom drop down and ajax.
    When I change, for example, to 20 lines per page and then go to next page, it sets iDisplayStart=020 instead of 20.
    I solved it by changing
    [code] oSettings._iDisplayLength = iDisplay; [/code]
    to
    [code] oSettings._iDisplayLength = parseInt(iDisplay);[/code]

    However I think this should be fixed in _fnCalculateEnd function
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I'm going to guess that you are using iDisplayStart or aLengthMenu or server-side processing and are giving a string rather than a numeric value somewhere. For certain features it is expected that numeric values are given, not strings.

    Allan
  • chubbytubstachubbytubsta Posts: 2Questions: 0Answers: 0
    edited March 2012
    Allen the bug still exitst when there is no length select box. Change the code to
    [code]
    if(oSettings.aanFeatures.l) {
    $('select', oSettings.aanFeatures.l).val( iDisplay );
    }
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I might be losing it - but where is that code in DataTables 1.9? I can't see it anywhere, or are you using a older version?

    Allan
  • chubbytubstachubbytubsta Posts: 2Questions: 0Answers: 0
    edited March 2012
    :)

    I'm using the 1.9 version but the code is in the plugin fnLengthChange.
    (plugins > api > fnLengthChange) It's a plug-in by Pedro Alves
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Oh I see! In that case I've now updated the plug-in :-) Thanks for flagging that up!

    Allan
This discussion has been closed.