Search and sorting not working with Ajax and Post.

Search and sorting not working with Ajax and Post.

bbrindzabbrindza Posts: 300Questions: 69Answers: 1

I am having a problem with sorting and searching with DataTables using Ajax and post method.

My application accepts column selections from the front-end by the user and passes these values as $-GET to the server side script to build the returned JSON.

I found that the $_GET is limited to the number of parmeters passed so I change it to use $_POST however when I made this change the DataTable search and sort stopped functioning.

What am I missing here?

 table = $( "#EmployeeTable" ).DataTable( {
      order: [[ 0, "asc" ]],
      lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
      iDisplayLength: 15,
      fixedHeader: true,
      dom: 'RlBfrtip',
      buttons: [
         'excelHtml5',
         'pdfHtml5'
     ],
      sPaginationType: "full_numbers",
      oLanguage: { sSearch: "Table Search: "},
      processing: true,
      serverSide: true,
      ajax: { url:  "ssp_EmployeeLoad.php",
              type: "POST",
              data: {locationCode: currentLocationCode,
                     fieldsSelected: fieldSelectionDataString,
                    }
              },
       columnDefs: [
                      { "width": "4em", "targets": 0 }

                      ],
       columns: colArray,
       colReorder: true,
       orderCellsTop: true,
       
  });//END .dataTable
<?php

$fieldsSelected = json_decode(($_POST['fieldsSelected']), true);
$locationCode = $_POST['locationCode'];

include('i5db2connect.php');

// DB table to use
$table = "LIB_1.EMPLOYEE";

// Table's primary key
$select = '';
$extraWhere = '';
$primaryKey = 'EMPLOYEE_NUMBER';

// Array of database columns 

foreach ($fieldsSelected as $key => $fields) {
    
    $fieldName=trim($fieldsSelected[$key]['fieldName']);
    
    $fieldDescription=trim($fieldsSelected[$key]['fieldDescription']);
   
    $columns[] = array('db' => $fieldName, 'dt'=> $fieldDescription);
    
} //End - foreach ($fieldsSelected as $key => $fieldName)


require( 'ssp.class.php' );

echo json_encode(
    SSP::simple( $_GET, $connection, $select, $table, $primaryKey, $columns, $extraWhere)
    );

?>

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394
    Answer ✓
    SSP::simple( $_GET, ....
    
  • bbrindzabbrindza Posts: 300Questions: 69Answers: 1

    Oh Lordy! How did I miss that. Thank you for you clear eyes Tangerine.

This discussion has been closed.