when the table after the event xhr completes the creation of all elements DOM?

when the table after the event xhr completes the creation of all elements DOM?

izumovizumov Posts: 178Questions: 14Answers: 0

the fact is that in my table one column contains elements input.which I need to access after downloading data from the server.
however, when trying to access immediately after the event xhr I fail because the required item is not there yet. Tell me which event is better for me to use for my purpose?

Replies

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    xhr triggers when the data has been returned, but not loaded. So in that event handler, you could use one() to set a one-off event handler on draw which will be called once the data is loaded.

    Colin

  • izumovizumov Posts: 178Questions: 14Answers: 0

    if I understand you correctly. then the code should look like

    $('#goods').on( 'xhr.dt', function () {
    var table=$('#goods').DataTable();
    alert('загрузка данных завершилась');
    table.one('draw',function(){
         var otborparsegood=sessionStorage .getItem('otborgood');
        if(otborparsegood!=null){otbortovar=JSON.parse (otborparsegood);
    recover_orders();
        alert('first draw');
                  };
    }); 
    

    I noticed that when I write code for the event page

    $('#goods').on( 'page.dt', function () {
    //var   pageNo = this.fnPagingInfo().iPage+1;
    sessionStorage .setItem('otborgood', JSON.stringify(otbortovar));
    var table=$('#orders').DataTable();})
    

    then the page navigation stops working. how can I change the code so that the page navigation is not canceled?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • izumovizumov Posts: 178Questions: 14Answers: 0
  • izumovizumov Posts: 178Questions: 14Answers: 0

    Could you tell me an event similar init to the degree of readiness of the table for an event occurring after the event xhr

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Could you tell me an event similar init to the degree of readiness of the table for an event occurring after the event xhr

    I'm not following, sorry. What do you want the event to do, and when?

    Colin

  • izumovizumov Posts: 178Questions: 14Answers: 0

    after download the page data, I want to find the page row containing the specific data in the 1st column and restore the value in input the input element of this row.
    but the problem is that this line may be outside the current displayed page and I get an error when trying to write to the input element, as I understand that it is not there. How to determine that the line is outside the current page, I have not yet come up with. I determine the row index by code

    indexes = table.rows().eq( 0 ).filter( function (rowIdx) {
        return table.cell( rowIdx, 0 ).data() === id_good ? true : false;
    

    can you tell me the idea of solving the problem?

  • izumovizumov Posts: 178Questions: 14Answers: 0

    is it possible to change the search code of the row index so that the search area is only the rows that are displayed on the current page?

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    You can use rows().every() instead of table.rows().eq( 0 ). However to answer your question use the rows() selector-modifier of {page:'current'}.

    Kevin

  • izumovizumov Posts: 178Questions: 14Answers: 0

    I experimented with the program in debug mode and found out that my problems begin when I go to another page, I remember the data from the first column in the array, but when the page changes, there are none
    and expression

    indexes = table.rows().eq( 0 ).filter( function (rowIdx) {
        return table.cell( rowIdx, 0 ).data() === id_good ? true : false;
    } );
    

    which I use to search for the target string gives value _Api(0)
    but I don’t understand what it is and how to process such a returned search result. Can you tell me something on this issue?

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin

    Could you try a simplified bit of code:

    indexes = table.rows( function (idx, data, node) {
      return data[0] === id_good;
    ).indexes();
    

    I'm not sure what id_good is or where it is being set though.

    Allan

  • izumovizumov Posts: 178Questions: 14Answers: 0

    Thank you for your advice. But I already managed to find out the source of the problem - this is the case when the line is not located - it just is not on this page, I just provided this case in the code (then nothing needs to be done) and the code began to work as it should.

This discussion has been closed.