Possible bug in the draw function

Possible bug in the draw function

madrianmadrian Posts: 6Questions: 1Answers: 0

I am using YADCF plugin with Datatables and I found a little glitch. I am trying to update a selector, but table_arg.fnDraw inside exFilterColumn function is reseting select filter value.

yadcf.initOnDtXhrComplete(function() { 
      yadcf.exFilterColumn(oTable, [[4, $("#yadcf-filter--mytable-4 option:eq(1)").val()]], true); 
   });

Daniel, developer of YADCF who has discovered the bug on Stackoverflow.

You can check on website https://bow.thingiverse.ml

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 9,792Questions: 25Answers: 2,258
    edited January 9

    That was fun, I hadn't looked at YADCF for awhile. Took a bit to figure out how yadcf.exFilterColumn works :smile:

    Not sure how the Datatables draw() API would affect the YADCF created input. Datatables has no knowledge of it.

    I built a simpler test case to replicate your issue:
    http://live.datatables.net/cecegoco/1/edit

    The problem, in my case, is actually with the yadcf.initOnDtXhrComplete event. It doesn't seem to work with server side processing. Likely it will work with client side ajax loaded tables. Although the behavior is a bit different then your example it highlights the issue. You can see that the event keeps running after each server side XHR response causing another search/response. The YADCF developer might be able to create a way to invoke that event once like one().

    One option is to use the init event which will execute after all the data is loaded and Datatables is finished initializing. This can be seen here:
    http://live.datatables.net/rekivubo/1/edit

    Kevin

  • madrianmadrian Posts: 6Questions: 1Answers: 0

    For some reason it doesn't work for me with init:

    $('#mytable').on( 'init.dt', function () {
         yadcf.exFilterColumn(oTable, [[4, '2/2020']], true);
     });
    

    I found one more problem: I am using the "Pipelining data to reduce Ajax calls for paging". It works pretty good If I am going forward in pages, but when I click to the last page and I am trying to go back I am getting empty result/or loading message. I tried with/without ysdcf, the problem is not with this module. I think it is the same problem with Show X result: I choose show 100 record and nothing happens. If I choose 50, first page is showing correctly, but not the others. I think it's something with page caching?

  • kthorngrenkthorngren Posts: 9,792Questions: 25Answers: 2,258

    For some reason it doesn't work for me with init:

    Did you change the table selector ID from #mytable to match your table's ID?

    It works pretty good If I am going forward in pages, but when I click to the last page and I am trying to go back I am getting empty result/or loading message.

    This doesn't have anything to do with YADCF. You can see the problem with the browser's Developer Tools > Network tab. Watch the XHR requests. Load the page you will see two requests; the first is the initial request then the second is the YADCF search value:

    columns[4][data]: week
    columns[4][name]: 
    columns[4][searchable]: true
    columns[4][orderable]: true
    columns[4][search][value]: 2/2020
    columns[4][search][regex]: false
    

    You can page through page 5 without an XHR request. This is due to the Pipelining. Clicking page 6 fetches another set of pipelined pages. Clicking on 478 I see an XHR request and response and the page displays. Clicking on 477 there is a request for:

    start: 4720
    length: 50
    

    There is a 200 OK response but no data. The place to start is to see why the server script is not sending data in the response. Go back to page 1 and it works fine.

    Kevin

  • madrianmadrian Posts: 6Questions: 1Answers: 0
    edited January 26

    Sorry for long response, I was on holiday.

    There is a 200 OK response but no data.

    You are right, it was a json_encode & UTF8 encoding problem. Now, I convert everything to UTF8, then json_encode works properly.

    So there is just one thing that I can't fix, the:

    For some reason it doesn't work for me with init:
    Did you change the table selector ID from #mytable to match your table's ID?

    My table ID is #mytable

    <table class="table table-bordered" style="width:100%" id="mytable">

    It should work like in your example, but for some reason it's not. :neutral:

    I even tried to manually set, but doesn't work either:

    $('#mytable').on( 'init.dt', function () {
         yadcf.exFilterColumn(oTable, [[4, '3/2020']], true);
      } );
    

    As you can see it shows up for a sec, then it's become hidden.

  • kthorngrenkthorngren Posts: 9,792Questions: 25Answers: 2,258
    Answer ✓

    Have you reached out to the YADCF developer? The select input is created and managed by the YADCF plugin. Ultimately it will need to be fixed by the YADCF developers. There may be a race condition that is causing the YADCF plugin to clear the input value.

    You could try setting the select value as a workaround:
    http://live.datatables.net/zediqoqe/1/edit

    I tried this after initially loading the table with the select not showing the value and it changed the input display:
    $("#yadcf-filter--mytable-4").val($("#yadcf-filter--mytable-4 option:eq(1)").val());

    Kevin

  • madrianmadrian Posts: 6Questions: 1Answers: 0

    Hi Kevin,

    It looks like we got a proper bug fix:

    https://github.com/vedmack/yadcf/issues/612#issuecomment-580306844

    Now, it's working properly. :)

Sign In or Register to comment.