Ajex reload did not work

Ajex reload did not work

Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

Link to test case:
Debugger code (debug.datatables.net): ozimov
Error messages shown: none
Description of problem:
I have a problem with the ajax.reload(). click on the button should get new data from the server and reload the datatable.
But in this case i see the new json data would send to the client, but the table did not reload the data.

I have no idea why this problem is. Other datatables did work without any problems. I tried table.ajax.url( 'url' ).load(), but this did not work too.

Did you have an idea where my problem is?

Andreas

My code:

$( function() {
  dtButtons = [];
  let key = 0;
  let keymax = yr.length - 1;

  editor = new $.fn.dataTable.Editor( {
    ajax: 'assets/php/pa-server-backend.php?anbe=2',
    display: 'bootstrap',
    template: '#cAnnual',
    idSrc: 'DT_RowId',
    fields: [
      {
        label: 'Annual:',
        name: 'annual',
      }
    ]
  } );

  dtButtons.push( {
    extend: 'create',
    editor: editor,
    text: '<i class="fa-regular fa-plus"></i>',
    titleAttr: 'Create new Annual best list for given year',
    className: 'text-blue bold',
    formButtons: [
      { text: 'Update', action: function() { this.submit(); }, className: 'btn-info mr-5' },
      { text: 'Cancel', action: function() { this.close(); }, className: 'btn-primary' }
    ],
    formTitle: '<i class="far fa-plus text-blue bold"></i> <span class="text-blue bold">Create new annual best</span>'
  } );

  dtButtons.push( {
    text: yr[key],
    titleAttr: 'Select annual best list',
    className: 'text-blue bold ml-5',
    action: function( e, dt, node, config ) {
      key = ( key == keymax ) ? 0 : key + 1;
      this.text( yr[key] );
      $( '#annualTitle' ).text( 'Jahresbestleistungen ' + yr[key] );
      dt.ajax.url( 'assets/php/pa-server-backend.php?anbe=1&y=' + yr[key] + '&g=' + gd + '&ag=' + ag );
      dt.ajax.reload();
    }
  } );

  let table = $( '#annual_best_12tbl' ).DataTable( {
    ajax: {
      url: 'assets/php/pa-server-backend.php?anbe=1&y=' + yr[key] + '&g=' + gd + '&ag=' + ag,
      type: 'POST'
    },
    autoWidth: false,
    select: true,
    serverSide: true,
    processing: true,
    ordering: false,
    pagingType: 'numbers',
    pageLength: 20,
    dom: "<'row'<'col-sm-12 DT_Buttons_Style'B>>rt<'row'<'col-sm-6'><'col-sm-6'>>",
    columnDefs: [
      { targets: [ 0, 2, 4, 7 ], className: 'text-center' },
    // { targets: [ 1, 3, 5 ] },
      { targets: [ 6, 8 ], className: 'text-right' },
      { targets: '_all', visible: true, searchable: false, orderable: false }
    ],
    columns: [
      { data: 'rank' },
      { data: 'name' },
      { data: 'birthday' },
      { data: 'club' },
      { data: 'course' },
      { data: 'stroke' },
      { data: 'swtime' },
      { data: 'points' },
      { data: 'updated_at' }
    ],
    buttons: {
      dom: {
        container: {
          className: 'dt-buttons btn-group'
        }
      },
      buttons: dtButtons
    },
    initComplete: function( data ) {
      $( '#annual_best_12tbl' ).removeClass( 'd-none' );
    }
  } );

} );

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    I think we'll need a link to a page showing the issue for this one. I don't immediately see anything wrong with the code above.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I have send you the login data via PN

    Andreas

Sign In or Register to comment.