Error Requested unknown parameter

Error Requested unknown parameter

rafaswrafasw Posts: 78Questions: 7Answers: 0
edited November 2018 in Free community support

Data Table

$(document).ready(function() {


      var advance = $('#advanced-table').DataTable( {
              
        
      dom: 'B<"clear">lfrtip',
  
    "processing": true,
    "serverSide": true,

      "ajax":{
                        url :"server_processing.php ", // json datasource
                        type: "post",  // method  , by default get
                        
                    },
         

      
          mark: true,
           columnDefs: [
            {
                targets: 1,
                className: 'noVis',
        
            },
            {
                "targets": [ 6 ],
                "visible": false
            },
            {
                "targets": [ 7 ],
                "visible": false
            }   
            
        ],
      
    buttons: {
        name: 'primary',

        buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print', 'colvis'  ]
    },
          
          
  
    
          //"language": {
                //"url": "http://cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json"
           // } 
          
   
    } );

    
    $('a.toggle-vis').on( 'click', function (e) {
        e.preventDefault();
 
        // Get the column API object
        var column = advance.column( $(this).attr('data-column') );

        // Toggle the visibility
        column.visible( ! column.visible() );
    } );  
    


// Setup - add a text input to each footer cell
    $('#advanced-table tfoot th').each( function () {
        var title = $(this).text();
        $(this).html( '<div class="md-input-wrapper"><input type="text" class="md-form-control" placeholder="Pesquisar '+title+'" /></div>' );
    } );
      // Apply the search
    advance.columns().every( function () {
        var that = this;
 
        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                that
                    .search( this.value )
                    .draw();
            }
        } );
    } );

    

    } );

server_processing.php

```
<?php
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "entt";

$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* Database connection end */

// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;

$columns = array(
// datatable column index => database column name
0 =>'ID',
1 =>'Nome',
2 => 'E-mail',
4 => 'Cidade',
5 => 'Estado',
6 => 'Cep',
7 => 'Data',
8 => 'Hora',
9 => 'Status'
);

// getting total number records without any search
$sql = "SELECT id, email, nome, cidade, estado, cep, data, hora ";
$sql.=" FROM usuarios";
$query=mysqli_query($conn, $sql) or die("server_processing.php: get usuarios");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.

$sql = "SELECT id, email, nome, cidade, estado, cep, data, hora ";
$sql.=" FROM usuarios WHERE 1=1";
if( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
$sql.=" AND ( id LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR nome LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR email LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR cidade LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR estado LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR cep LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR data LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR hora LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("server_processing.php: get usuarios");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($conn, $sql) or die("server_processing.php: get usuarios");

$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();

$nestedData[] = $row["id"];
$nestedData[] = $row["nome"];
$nestedData[] = $row["email"];
$nestedData[] = $row["cidade"];
$nestedData[] = $row["estado"];
$nestedData[] = $row["cep"];
$nestedData[] = $row["data"];
$nestedData[] = $row["hora"];
$data[] = $nestedData;

}

$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);

echo json_encode($json_data); // send data as json format

<?php > ``` ?>

DataTables warning: table id=advanced-table - Requested unknown parameter '8' for row 0, column 8. For more information about this error, please see http://datatables.net/tn/4

«1

Replies

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Did you follow the troubleshooting steps in the link provided in the error?

    I suspect the problem is that you are returning 8 elements for each row but have more than 8 columns defined in your table.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    I understand, but how do I know what is being returned? because it is only set to fetch any database that is in the table

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    I found the problem

    array( 'db' => 'id', 'dt' => 0 ), array( 'db' => 'nome', 'dt' => 1 ), array( 'db' => 'email', 'dt' => 2 ), array( 'db' => 'cidade', 'dt' => 3 ), array( 'db' => 'estado', 'dt' => 4 ), array( 'db' => 'cep', 'dt' => 5 ), array( 'db' => 'data', 'dt' => 6 ), array( 'db' => 'hora', 'dt' => 7 ) , array( 'db' => 'status', 'dt' => 8 )
    the status field that is the 8 field, it has buttons will not be used to search anything, how do I disable it via array, because when I remove the line it gives this error message

    DataTables warning: table id=advanced-table - Requested unknown parameter '8' for row 0, column 8. For more information about this error, please see http://datatables.net/tn/4

    field 8 is it a hidden field how do I disable it or put it blank in the array?

    thanks

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    how do I call only the 7 fields, from 0 to 7 on the server side,

    IGNORE field 8

    waiting, thank you in advance

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @rafasw ,

    It looks like you haven't defined the columns with colunms in the table initialisation - therefore DataTables will try to display them all. This example here should help.

    If still no joy, can you link to a test case please.

    Cheers,

    Colin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    nor boot without field 8



    $(document).ready(function() { var advance = $('#advanced-table').DataTable( { dom: 'B<"clear">lfrtip', "processing": true, "serverSide": true, "responsive": true, "ajax":"server_processing.php", "columns": [ { "data": "id" }, { "data": "nome" }, { "data": "email" }, { "data": "cidade" }, { "data": "estado" }, { "data": "cep" }, { "data": "data" }, { "data": "hora" }, ], mark: true, columnDefs: [ { targets: 1, className: 'noVis', }, { "targets": [ 6 ], "visible": false }, { "targets": [ 7 ], "visible": false }, ], buttons: { name: 'primary', buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print', 'colvis' ] }, //"language": { //"url": "http://cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json" // } } ); $('a.toggle-vis').on( 'click', function (e) { e.preventDefault(); // Get the column API object var column = advance.column( $(this).attr('data-column') ); // Toggle the visibility column.visible( ! column.visible() ); } ); // Setup - add a text input to each footer cell $('#advanced-table tfoot th').each( function () { var title = $(this).text(); $(this).html( '<div class="md-input-wrapper"><input type="text" class="md-form-control" placeholder="Pesquisar '+title+'" /></div>' ); } ); // Apply the search advance.columns().every( function () { var that = this; $( 'input', this.footer() ).on( 'keyup change', function () { if ( that.search() !== this.value ) { that .search( this.value ) .draw(); } } ); } ); } );

    initiates but this error

    DataTables warning: table id=advanced-table - Requested unknown parameter 'id' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4



    $(document).ready(function() { var advance = $('#advanced-table').DataTable( { dom: 'B<"clear">lfrtip', "processing": true, "serverSide": true, "responsive": true, "ajax":"server_processing.php", "columns": [ { "data": "id" }, { "data": "nome" }, { "data": "email" }, { "data": "cidade" }, { "data": "estado" }, { "data": "cep" }, { "data": "data" }, { "data": "hora" }, { "data": "status" }, ], mark: true, columnDefs: [ { targets: 1, className: 'noVis', }, { "targets": [ 6 ], "visible": false }, { "targets": [ 7 ], "visible": false }, ], buttons: { name: 'primary', buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print', 'colvis' ] }, //"language": { //"url": "http://cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json" // } } ); $('a.toggle-vis').on( 'click', function (e) { e.preventDefault(); // Get the column API object var column = advance.column( $(this).attr('data-column') ); // Toggle the visibility column.visible( ! column.visible() ); } ); // Setup - add a text input to each footer cell $('#advanced-table tfoot th').each( function () { var title = $(this).text(); $(this).html( '<div class="md-input-wrapper"><input type="text" class="md-form-control" placeholder="Pesquisar '+title+'" /></div>' ); } ); // Apply the search advance.columns().every( function () { var that = this; $( 'input', this.footer() ).on( 'keyup change', function () { if ( that.search() !== this.value ) { that .search( this.value ) .draw(); } } ); } ); } );
  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    I think the problem now is that you are returning an array of arrays but you are telling Datatables that the data is an array of objects. Instead of this:

        "columns": [
                { "data": "id" },
                { "data": "nome" },
                { "data": "email" },
                { "data": "cidade" },
                { "data": "estado" },
                { "data": "cep" },
                { "data": "data" },
                { "data": "hora" },
                 
            ],
    

    Try this:

        "columns": [
                { "data": 0 },
                { "data": 1 },
                { "data": 2 },
                { "data": 3 },
                { "data": 4 },
                { "data": 5 },
                { "data": 6 },
                { "data": 7 },
                 
            ],
    

    This will tell Datatables to use the desired array elements and ignore the others. The status can remain in the data retrieved from the server but Datatables won't display it. And, with any luck, no more errors.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0
    edited November 2018
    "columns": [
            { "data": 0 },
            { "data": 1 },
            { "data": 2 },
            { "data": 3 },
            { "data": 4 },
            { "data": 5 },
            { "data": 6 },
            { "data": 7 },
    
        ],
    

    Does not open the table or start.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It would be worth posting a couple of lines of the Ajax response.

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited November 2018

    Does not open the table or start.

    What happens, do you get any alert or browser console errors?

    And as Colin mentioned post a sample of the ajax response seen in the browser.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    data_tablec.js



    $(document).ready(function() { var advance = $('#advanced-table').DataTable( { dom: 'B<"clear">lfrtip', "processing": true, "serverSide": true, "responsive": true, "ajax":"server_processing.php", "columns": [ { "data": 0 }, { "data": 1 }, { "data": 2 }, { "data": 3 }, { "data": 4 }, { "data": 5 }, { "data": 6 }, { "data": 7 } ], mark: true, columnDefs: [ { targets: 1, className: 'noVis', }, { "targets": [ 6 ], "visible": false }, { "targets": [ 7 ], "visible": false }, ], buttons: { name: 'primary', buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print', 'colvis' ] }, //"language": { //"url": "http://cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json" // } } ); $('a.toggle-vis').on( 'click', function (e) { e.preventDefault(); // Get the column API object var column = advance.column( $(this).attr('data-column') ); // Toggle the visibility column.visible( ! column.visible() ); } ); // Setup - add a text input to each footer cell $('#advanced-table tfoot th').each( function () { var title = $(this).text(); $(this).html( '<div class="md-input-wrapper"><input type="text" class="md-form-control" placeholder="Pesquisar '+title+'" /></div>' ); } ); // Apply the search advance.columns().every( function () { var that = this; $( 'input', this.footer() ).on( 'keyup change', function () { if ( that.search() !== this.value ) { that .search( this.value ) .draw(); } } ); } ); } );

    server_processing.php

     <?php
    $table = 'usuarios';
    $primaryKey = 'id';
    $columns = array(
    array( 'db' => 'id', 'dt' => 0 ),
    array( 'db' => 'nome', 'dt' => 1 ),
    array( 'db' => 'email', 'dt' => 2 ),
    array( 'db' => 'cidade', 'dt' => 3 ),
    array( 'db' => 'estado', 'dt' => 4 ),   
    array( 'db' => 'cep', 'dt' => 5 ),
    array( 'db' => 'data', 'dt' => 6 ),
    array( 'db' => 'hora', 'dt' => 7 )      
    );
    
    $sql_details = array(
    'user' => 'root',
    'pass' => '',
    'db' => 'entt',
    'host' => 'localhost'
    );
    
    require( 'ssp.class.php' );
    
    echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );
    

    if you want as you requested or generate XHR, nor open a table gets locked,

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Could you post that Ajax response, please. That would be the most useful, so we can see what's being sent back to DataTables.

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    how do I post an ajax response? thanks

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    navegator > developer tool > network > XHR ( it is ? )

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Yes. You can follow the steps in this technote:
    https://datatables.net/manual/tech-notes/1

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    ERROR
    DataTables warning: table id=advanced-table - Requested unknown parameter '8' for row 0, column 8. For more information about this error, please see http://datatables.net/tn/4

    Response

    {"draw":1,"recordsTotal":3454,"recordsFiltered":3454,"data":[["1","Infomax","rafael@infomaxlondrina.com","Londrina","PR","86039280","21\/11\/2018","13:42"],["2","Vanderlei Jos\u00e9 padilha","Vgajpad@outlook.com","Curitiba","Paran\u00e1","818.200.20","15\/11\/2018","10:01"],["5","Gabriel Selke Jorge","sjxgabrielx@outlook.com.br","Florian\u00f3polis","SC","880.493.60","16\/09\/2018","10:42"],["6","Douglas Nunes","xxx@hotmail.com","S\u00e3o Paulo","SP","058.640.30","16\/09\/2018","10:42"],["7","Luan Oliveira","luan-ba-gc@hotmail.com","SALVADOR","BAHIA","402.550.00_","16\/09\/2018","10:42"],["8","jozeilton raposo da costa","jozeiltonraposo@gmail.com","goi\u00e2nia","goi\u00e1s","747.110.20","16\/09\/2018","10:42"],["9","Thiago Perci gon\u00e7alves","thiago_per_ci@hotmail.com","cachoeirinha","Rio grande do Sul","949.605.20","16\/09\/2018","10:42"],["10","RAFAEL FRANCISCO DOS SANTOS","volks3000@hotmail.com","RECIFE","Pernambuco","520.902.30","16\/09\/2018","10:42"],["11","Isaque Xisto Silva","isaquexisto@gmail.com","Jo\u00e3o Monlevade","Minas Gerais","359.312.84","16\/09\/2018","10:42"],["12","Estevao Ricier Ferreira","estevaoferreira7021@gmail.com","moema","minas gerais","356.040.00","16\/09\/2018","10:42"],["13","David Jos\u00e9 MAruqes Aguiar","geralinformatica10@gmail.com","belem","PAR\u00c1","661.232.220","16\/09\/2018","10:42"],["14","thiago caldeira birro leite","thiagocbirro@hotmail.com","contagem","minas gerais","322.802.30","16\/09\/2018","10:42"],["15","Felippe Lino Lima","felippe.flip@gmail.com","Sumar\u00e9","S\u00e3o Paulo","013.181.752","16\/09\/2018","10:42"],["16","Eder Silva do Nascimento","eder_sil@live.com","Florian\u00f3polis","santa catarina","880.484.21","16\/09\/2018","10:42"],["17","Edson Fernandes de Jesus","eddy.sistema@gmail.com","Pilar do Sul","Sao Paulo","181.850.00","16\/09\/2018","10:42"],["18","ANDRE DE JESUS","adj.andre@hotmail.com","VIT\u00d3RIA","ES","290.560.30","16\/09\/2018","10:42"],["19","Fernando Torres","fernando.torres.2015@outlook.com","Praia grande","S\u00e3o paulo","117.243.30","16\/09\/2018","10:42"],["20","Juan Carlos","jcproducciones742@gmail.com","Jacare\u00ed","SP","123.276.81","16\/09\/2018","10:42"],["21","Rosberg Tavares Lima","BERG-NIGHT@HOTMAIL.COM","PORTO VELHO","ROND\u00d4NIA","768.115.08","16\/09\/2018","10:42"],["22","Davi Teles da Silva","daviteles14@hotmail.com","S\u00e3o Vicente","S\u00e3o Paulo","113.203.10","16\/09\/2018","10:42"],["23","Renato Cleyner Ferreira","renatocleyner@gmail.com","Viana","espirito santo","291.353.50","16\/09\/2018","10:42"],["24","Silvio Mamedio","silvio1234567810@gmail.com","Gandu","Bahia","454.500.00","16\/09\/2018","10:42"],["25","NELCY SANTIAGO DE SOUSA","NELCYGA@HOTMAIL.COM.BR","UB\u00c1","MINAS GERAIS","365.000.000","16\/09\/2018","10:42"],["26","Za warudo","respawcraft@gmail.com","Rio de janeiro","Rio de janeiro","331.777.222","16\/09\/2018","10:42"],["27","Jackson Lino de Oliveira Amarante","jacksonlinoc360@gmail.com","Fortaleza","Ceara","607.604.80","16\/09\/2018","10:42"],["28","RAFAEL ARAUJO","rafael.araujo_mbamaraba@outlook.com","marab\u00e1-pa","par\u00e1","","16\/09\/2018","10:42"],["29","RAFAEL OLIVEIRA BORRASCA","Fury_RafizZ@hotmail.com","MARINGA","PR - Paran\u00e1","870.251.60","16\/09\/2018","10:42"],["30","Julio Moura","jcmouravais@gmail.com","Americo Brasiliense","Sao Paulo","148.200.00","16\/09\/2018","10:42"],["31","Emerson Santos Simonetti","apollo440@hotmail.com","Parnamirim","RN","591.516.10","16\/09\/2018","10:42"],["32","Gabriel Gaspar da Silva Sobrinho","gabriel290_@hotmail.com","Itabuna","BA","456.004.61","16\/09\/2018","10:42"],["33","alexandre viera","xlandre@gmail.com","cabo frio","rio de janeiro","289.256.86","06\/11\/2018","01:17"],["34","carlos  alberto  da costa  pfeiffer","kiki_pfeiffer_@hotmail.com","","","","16\/09\/2018","10:42"],["35","PAULO ROBERTO MARCON","paromarc@yahoo.com.br","LAGES","SC","885.040.30_","16\/09\/2018","10:42"],["36","Danimar Gratieri Colombo","danigcolombo@hotmail.com","Tapejara","RS","999.500.00_","05\/11\/2018","16:38"],["37","Bruno","bruno_bragioon@hotmail.com","Osasco","Solteiro","061.402.40","16\/09\/2018","10:42"],["38","Jonathan Frederico Calson","jonycats95@gmail.com","Gaspar","Santa Catarina","891.198.99","16\/09\/2018","10:42"],["39","Rafael Lopes Borges","spy_inf@hotmail.com","nova friburgo","RJ","028.630.320","16\/09\/2018","10:42"],["40","Fabricio Henrique Gallo","fabriciohenrique789@hotmail.com","campinas","sao paulo","130.541.32","16\/09\/2018","10:42"],["41","Marcelo Moglia Proen\u00e7a","marcelopro@hotmail.com.br","Corumb\u00e1","MS","793.043.80_","16\/09\/2018","10:42"],["42","Orlailton de Araujo Santos","orlailtonaraujo@gmail.com","Pinh\u00e3o","Sergipe","495.170.00","16\/09\/2018","10:42"],["43","farley","farleylikestone@hotmail.com","pao","sp","085.556.80","16\/09\/2018","10:42"],["44","Pedro Leandro","pedroleandro917@gmail.com","araruna","parana","872.600.000","16\/09\/2018","10:42"],["45","Luiz Fernando","lf1405@hotmail.com","","","","16\/09\/2018","10:42"],["46","Davi Da Silva Sperfeld","davisperfeld@hotmail.com","bra\u00e7o do norte","SANTA CATARINA","887.500.00_","16\/09\/2018","10:42"],["47","Iago Oliveira","iagim131@gmail.com","","","","16\/09\/2018","10:42"],["48","Cleiton Luiz","cleitoncls@hotmail.com","Goi\u00e2nia","GO","742.652.10","16\/09\/2018","10:42"],["49","ERIC FERREIRA","evsf123456@gmail.com","DELMIRO GOUVEIA","ALAGOAS","574.809.71","16\/09\/2018","10:42"],["50","Kelton Vieira Rudenas","keltonrudenas@live.com","Campo Grande","Mato Grosso do Sul","790.863.60","16\/09\/2018","10:42"],["51","Anisio Pl\u00e1cido","anisu@hotmail.com.br","Macei\u00f3","AL","570.364.30","16\/09\/2018","10:42"],["52","Leonardo Lacerda","leonardolacerdab@gmail.com","Guarani","Minas Gerais","361.600.00","16\/09\/2018","10:42"]]}
    
  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    Headers

    Request URL: http://localhost/entt/admin/server_processing.php?draw=1&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=2&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=3&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=4&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=5&columns%5B5%5D%5Bname%5D=&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=6&columns%5B6%5D%5Bname%5D=&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=true&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B7%5D%5Bdata%5D=7&columns%5B7%5D%5Bname%5D=&columns%5B7%5D%5Bsearchable%5D=true&columns%5B7%5D%5Borderable%5D=true&columns%5B7%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B7%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B8%5D%5Bdata%5D=8&columns%5B8%5D%5Bname%5D=&columns%5B8%5D%5Bsearchable%5D=true&columns%5B8%5D%5Borderable%5D=true&columns%5B8%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B8%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=50&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1542816313198
    Request Method: GET
    Status Code: 200 OK
    Remote Address: [::1]:80
    Referrer Policy: no-referrer-when-downgrade
    Accept: application/json, text/javascript, */*; q=0.01
    Accept-Encoding: gzip, deflate, br
    Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
    Connection: keep-alive
    Cookie: PHPSESSID=allfipkrs4siatd3ddfm5be6q7; _ga=GA1.1.204095894.1542209749; _gid=GA1.1.1495562599.1542814957; _gat=1
    Host: localhost
    Referer: http://localhost/entt/admin/usuarios.php
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 OPR/56.0.3051.104
    X-Requested-With: XMLHttpRequest
    draw: 1
    columns[0][data]: 0
    columns[0][name]: 
    columns[0][searchable]: true
    columns[0][orderable]: true
    columns[0][search][value]: 
    columns[0][search][regex]: false
    columns[1][data]: 1
    columns[1][name]: 
    columns[1][searchable]: true
    columns[1][orderable]: true
    columns[1][search][value]: 
    columns[1][search][regex]: false
    columns[2][data]: 2
    columns[2][name]: 
    columns[2][searchable]: true
    columns[2][orderable]: true
    columns[2][search][value]: 
    columns[2][search][regex]: false
    columns[3][data]: 3
    columns[3][name]: 
    columns[3][searchable]: true
    columns[3][orderable]: true
    columns[3][search][value]: 
    columns[3][search][regex]: false
    columns[4][data]: 4
    columns[4][name]: 
    columns[4][searchable]: true
    columns[4][orderable]: true
    columns[4][search][value]: 
    columns[4][search][regex]: false
    columns[5][data]: 5
    columns[5][name]: 
    columns[5][searchable]: true
    columns[5][orderable]: true
    columns[5][search][value]: 
    columns[5][search][regex]: false
    columns[6][data]: 6
    columns[6][name]: 
    columns[6][searchable]: true
    columns[6][orderable]: true
    columns[6][search][value]: 
    columns[6][search][regex]: false
    columns[7][data]: 7
    columns[7][name]: 
    columns[7][searchable]: true
    columns[7][orderable]: true
    columns[7][search][value]: 
    columns[7][search][regex]: false
    columns[8][data]: 8
    columns[8][name]: 
    columns[8][searchable]: true
    columns[8][orderable]: true
    columns[8][search][value]: 
    columns[8][search][regex]: false
    order[0][column]: 0
    order[0][dir]: asc
    start: 0
    length: 50
    search[value]: 
    search[regex]: false
    _: 1542816313198
    
  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Thanks for the information.

    Your JSON is returning 8 columns (0 -7):

        "draw": 1,
        "recordsTotal": 3454,
        "recordsFiltered": 3454,
        "data": [
            ["1", "Infomax", "rafael@infomaxlondrina.com", "Londrina", "PR", "86039280", "21\/11\/2018", "13:42"],
            ["2", "Vanderlei Jos\u00e9 padilha", "Vgajpad@outlook.com", "Curitiba", "Paran\u00e1", "818.200.20", "15\/11\/2018", "10:01"],
    .....
    

    The above config you show 8 columns (0 - 7) so that should match:

     "columns": [
                { "data": 0 },
                { "data": 1 },
                { "data": 2 },
                { "data": 3 },
                { "data": 4 },
                { "data": 5 },
            { "data": 6 },
            { "data": 7 }
           ],
    

    However in the request Datatables is requesting 9 columns (0 - 9):

    columns[0][data]: 0
    columns[0][name]:
    columns[0][searchable]: true
    columns[0][orderable]: true
    columns[0][search][value]:
    columns[0][search][regex]: false
    ......
    columns[8][data]: 8
    columns[8][name]:
    columns[8][searchable]: true
    columns[8][orderable]: true
    columns[8][search][value]:
    columns[8][search][regex]: false
    

    There is something inconsistent about the config versus what is being sent. Are you sure the correct data_tablec.js is being loaded? Maybe you should try clearing the browser's cache.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    I cleaned the cache and the table opens blank without any item without xhr, with nothing

  • rafaswrafasw Posts: 78Questions: 7Answers: 0
    edited November 2018
     "columns": [
                { "data": 0 },
                { "data": 1 },
                { "data": 2 },
                { "data": 3 },
                { "data": 4 },
                { "data": 5 },
                { "data": 6 },
                { "data": 7 },
                            { "data": 8 }
    
    $columns = array(
    array( 'db' => 'id', 'dt' => 0 ),
    array( 'db' => 'nome', 'dt' => 1 ),
    array( 'db' => 'email', 'dt' => 2 ),
    array( 'db' => 'cidade', 'dt' => 3 ),
    array( 'db' => 'estado', 'dt' => 4 ),   
    array( 'db' => 'cep', 'dt' => 5 ),
    array( 'db' => 'data', 'dt' => 6 ),
    array( 'db' => 'hora', 'dt' => 7 ),
    array( 'db' => 'status', 'dt' => 8 )        
    );
    

    only works if I add the field 8 and status, if I remove both opens the blank xhr and the data table does not work is neither loaded, field 8 and status is a column of only buttons in HTML as I remove from the array

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    If the table is not loading then that suggests you are getting an error. Check your browser's console for errors.

    Can you post a link to your page? Its at the point that its difficult to help troubleshoot without actually seeing the issue.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    ok I'll post a template online to take a look

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    http://www.twb.net.br/Ent/admin/usuarios.php
    User:teste@teste.com.br
    Pass;20406080

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    I logged in but not sure which option to select to look at your issue. Please provide the steps to see the problem page.

    Kevin

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited November 2018

    I figured out which page to look at.

    You have 9 columns in your table.

                  <tr>
                    <th style="width: 10px;">ID</th>
                    <th style="width: 200px;">Nome</th>
                    <th style="width: 200px;">E-mail</th>
                    <th style="width: 80px;">Cidade</th>
                    <th style="width: 80px;">Estado</th>
                    <th style="width: 60px;">Cep</th>
                    <th style="width: 60px; ">Data</th>
                    <th style="width: 30px;">Hora</th>
                    <th style="width: 80px;">Status</th>
        
                  </tr>
    

    But you have defined 8 columns in Datatables:

     "columns": [
                { "data": 0 },
                { "data": 1 },
                { "data": 2 },
                { "data": 3 },
                { "data": 4 },
                { "data": 5 },
                { "data": 6 },
                { "data": 7 }
     ],
    

    You need to define all the columns in Datatables. You can do something like this:

     "columns": [
                { "data": 0 },
                { "data": 1 },
                { "data": 2 },
                { "data": 3 },
                { "data": 4 },
                { "data": 5 },
                { "data": 6 },
                { "data": 7 },
                {data: null,
                  defaultContent: ''
                },
     ],
    

    This will tell Datatables about the 9th column and defaultContent will be used to place empty content in the table. You could put your HTML to build the buttons in defaultContent parameter. Or you can use columns.render to build the buttons, depending on your needs. You need to have Datatables generate data for that column to place in the table.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0
    edited November 2018

    then the defaultcontent leaves the field blank, some days are not complete, you can not keep the data just deactivating the data: null, because if you want to leave the field defaultContent:' ', it is blank and can not return the data. same data from the table while

    is there any way to leave it normal without defaultcontent and at array time, leave the array empty?

    array( 'db' => 'status', 'dt' =>8)  
    
    

    leave this array empty ? thanks

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited November 2018

    Like I said you can use defaultContent to display the buttons or whatever you want. I provided an incorrect link to columns.defaultContent in my last post. The examples in this link columns.defaultContent will give you an idea. Or you can look at the examples in the columns.render.

    Basically there are two choices:

    1. Return the status in your JSON response
    2. Generate the data for the column using columns.defaultContent or columns.render.

    You can combine 1 and 2 and return the status then use columns.render to build buttons or whatever you want to do based on the data in status.

    The table rows you have in the DOM are overwritten when you use the Ajax call. The buttons you have in column 9 will not be there.

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    But if I leave the

     defaultContent: "",
    

    the field goes blank, how do I keep the buttons that are in php?

    Button Edit

    <button type="button" class="btn btn-inverse-info waves-effect waves-light " data-toggle="tooltip" data-placement="top" title="" data-original-title="Editar" aria-describedby="tooltip647345"><a href="?acao=Alterar&id_usuario=<?php echo $dadosusuario[id];?>"><i class="zmdi zmdi-edit" style="font-size:20px; color:#0A94E1"></i></a>
                      </button>
    

    Button Delete

    <button type="button" class="btn btn-inverse-danger waves-effect waves-light " data-toggle="tooltip" data-placement="top" title="" data-original-title="Excluir"><a href="?Excluir=ok&id_usuario=<? echo $dadosusuario[id]; ?>" onClick="return pergunta();"><i class="zmdi zmdi-delete" style="font-size:20px; color:#C80306"></i></a>
                                    </button>
    

    I will have to change everything, it will mess up my system as I do for the defaultContent: "", do not clear the field

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited November 2018

    Looks like you are using some of the data to create the buttons like <a href="?Excluir=ok&id_usuario=<? echo $dadosusuario[id]; ?>". You will need to use columns.render to generate the buttons. I'm not sure of the specifics of the data you are using but this example may help you get started:
    http://live.datatables.net/qemodapi/1/edit

    Kevin

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Here is an example of buttons being displayed using columns.defaultContent:
    http://live.datatables.net/xijecupo/1/edit

    Kevin

This discussion has been closed.