Datatables not work

Datatables not work

danish123_123danish123_123 Posts: 3Questions: 1Answers: 0

On page load ,i send a ajax request and get a table from the server.I receive the ajax request in php and get the data from the database and embet it with table and send the response by using echo json_encdoe($form)
I'm using datatables with this form but it's not work

Answers

  • danish123_123danish123_123 Posts: 3Questions: 1Answers: 0

    $form = '';
    $form .= '<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">';
    $form .= '

    '; $form .= ''; $form .= '
    '; $form .= '
    '; $form .= '
    '; $form .= '
    '; $form .= '
    Detaljer
    '; $form .= '
    '; $form .= ''; $form .= ''; $form .= '
    '; $form .= '
    '; $form .= '
    '; $form .= '
    '; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $attributes = array('ADMIN' , 'MANAGER'); $user = ret_user($attributes); if($user==true){ $form .= ''; }else{ $form .= ''; } $form .= ''; $form .= ''; $form .= ''; foreach($data['jobs'] as $value){ $form .= ''; $form .= ''; if(!empty($value['color']) && $value['color'] == 'red'){ $color = 'red'; }else{ $color ='white'; } $form .= ''; $form .= ''; $form .= ''; if($value['job_status']==2){ $Datum = $value['job_end']; }else{ $Datum = "P책g책r"; } $form .= ''; $form .= ''; $arr = ''; foreach ($value['items'] as $key => $item) { if(isset($item['item_name']) && !empty($item['item_name'])){ $arr = $item['item_name'].', '; }else{ $arr = ''; } } $form .= ''; // $form .= ''; $form .= ''; $attributes = array('ADMIN' , 'MANAGER'); $user = ret_user($attributes); if($user==true){ $form .= ''; } $form .= ''; $form .= ''; } $form .= ''; $form .= '
    Nr.Reg.NrFabrikatDatumLev.DatumKundTj채nstNoteringPrisRedigering
    '. $value['id'] .''. $value['carno'].''.$value['name'].''. $value['job_date'].''.$Datum.''.$value['customer_name'].''.$arr.''. ucwords($value['comment']).''.$value['total_price'].''; $form .= '
    '; $attributes = array('ADMIN' , 'MANAGER','USER'); $user = ret_user($attributes); if($user==true){ if($value['job_status']==1){ $form .= ''; }else{ $form .= ''; } } $attributes = array('ADMIN' , 'MANAGER'); $user = ret_user($attributes); if($user==true){ $form .= ''; $form .= ''; $form .= ''; } $form .= '
    '; $form .= '
    '; $form .= '
    '; $form .= '
    '; $form .= '
    '; $form .= ''; $form .= '

    ';
    // $form .= '';
    $form .= '';
    $form .= '';
    $form .= "jQuery(document).ready(function($){"; $form .= "$('#select_all').on('click',function(){"; $form .= "if(this.checked){"; $form .= "$('.checkbox').each(function(){"; $form .= "this.checked = true;"; $form .= "});"; $form .= "}else{"; $form .= "$('.checkbox').each(function(){"; $form .= "this.checked = false;"; $form .= " });"; $form .= "}"; $form .= " });"; $form .= "});"; $form .= "jQuery('#select_all_form').on('submit',function(e){"; $form .= "e.preventDefault();"; $form .= "var form = $(this);"; $form .= "$.ajax({"; $form .= "url : base_url + 'home/bulkaction',"; $form .= "type: 'POST',"; $form .= "data : form.serialize(),"; $form .= "dataType: 'json',"; $form .= "success:function(res){"; $form .= "if(res.status == 'true'){"; $form .= "alert(res.msg);"; $form .= "$('#select_all_form')[0].reset();"; $form .= "}else{"; $form .= "alert(res.msg);"; $form .= "}"; $form .= "}"; $form .= "});"; $form .= ""; $form .= "$.ajax({"; $form .= "url : base_url + 'home/get_data',"; $form .= "type: 'GET',"; $form .= "dataType: 'json',"; $form .= "success: function(res){"; $form .= "$('#table_data').html(res);"; $form .= "}"; $form .= "});"; $form .= ""; $form .= "$('#mydatatable').DataTable();"; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= "});"; $form .= "";
    echo json_encode($form);

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406

    Please use markdown to highlight your code. See below.

  • danish123_123danish123_123 Posts: 3Questions: 1Answers: 0
  • allanallan Posts: 61,690Questions: 1Answers: 10,101 Site admin

    Why are you encoding Javascript as JSON? That won't work unless you are using eval or something similarly unsafe on the client-side?

    I don't really get what the code is trying to do I'm afraid. If you could link to a test case (per the forum rules) that would be useful.

    Allan

This discussion has been closed.