how to make multiple data tables pass id

how to make multiple data tables pass id

rafaswrafasw Posts: 74Questions: 7Answers: 0
edited December 2023 in General

how do I pass the id of each data table to java script

PHP ( advanced-table-<? $dadosforuns['id']; ?> )

<table id="advanced-table-<? $dadosforuns['id'];  ?>" class="table dt-responsive table-striped table-bordered nowrap" width="100%">

Java script ( #advanced-table- ** how to send php id ** )

      var advance = $('#advanced-table').DataTable(
          $.extend( advance, searchOptions )
      );

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,765Questions: 1Answers: 10,111 Site admin
    Answer ✓

    If you are generating your Javascript using PHP, then pass it in just as you are doing for your HTML. If you aren't generating the Javascript with PHP, then could you set up a Javascript variable that will contain an array of the ids. Or if your table have all the same init options, just use a class selector:

    $('table.table').DataTable(
        $.extend( advance, searchOptions )
    );
    

    Allan

  • rafaswrafasw Posts: 74Questions: 7Answers: 0

    sorted out code:


    window.foruns_id = <?php echo $foruns_id;?> // declare as global variable var foruns_id = window.foruns_id; //console.log('#advanced-table-'+ foruns_id ); var advance = $('#advanced-table-'+ foruns_id ).DataTable( {

    thanks Alan

Sign In or Register to comment.