scrollX giving space between table head and body

scrollX giving space between table head and body

mrahmanmrahman Posts: 5Questions: 2Answers: 0

I know the problem but I dont know how to fix it. I passed dataTable from jquery ajax request and set scrollX : true. it give me gap space between table head and body. everything is good without the scrollX. I think the gap caused by the margin-bottom style for table. the scrollX properties split up the table, so the table head part as a single <table> and the body part as single <table>.

is that some kind of bug? I'm new in dataTable and I'm sorry for my english. I dont know how to provide the controller on live.datatables.net, so I'm not provided the code, just tell me if I should provide the code somehow.

Answers

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • mrahmanmrahman Posts: 5Questions: 2Answers: 0

    I'm not sure is it goes like this? http://live.datatables.net/rumofiku/1/edit?html,js,output

    im not sure where I should put the controller code, so I just put it here, and here is the controller called from ajax request:

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    use PhpOffice\PhpSpreadsheet\IOFactory;
    use PhpOffice\PhpSpreadsheet\Spreadsheet;
    use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
    
    class Upload extends CI_Controller {
        public function index() {
                if($_FILES["data_file_input"]["name"] != '') {
                    $allowed_extension = array('xls', 'xlsx', 'csv');
                    $file_array = explode(".", $_FILES['data_file_input']['name']);
                    $file_extension = end($file_array);
                    if(in_array($file_extension, $allowed_extension)) {
                        $file_name = time() . '.' . $file_extension;
                        move_uploaded_file($_FILES['data_file_input']['tmp_name'], $file_name);
                        $file_type = \PhpOffice\PhpSpreadsheet\IOFactory::identify($file_name);
                        $reader = \PhpOffice\PHPSpreadsheet\IOFactory::createReader($file_type);
    
                        $spreadsheet = $reader->load($file_name);
    
                        unlink($file_name);
    
                        $data = $spreadsheet->getActiveSheet()->toArray();
                        foreach($data as $row => $value){
                            if ($row == 0) {
                        foreach ($value as $offvalue) {
                            $data_colNames[] = $offvalue;
                            $data_thead[] = array(
                                'data'  => $offvalue,
                            'title' => $offvalue
                            );
                        }
                            } else {
                        $data_tbody[] = array_combine($data_colNames, $value);
                        }
                       }    
                  $data_json = array('data' => $data_tbody, 'columns' => $data_thead);
    
                  echo json_encode($data_json);
                  } else {
                      $message = '<div class="alert alert-danger">Only .xls or .xlsx file allowed</div>';
                  }
              } else {
                 $message = '<div class="alert alert-danger">Please Select File</div>';
              }
          }    
    }
    
  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    The problem you described is hard to diagnose without seeing the issue, so we really need a link to your page or a test case that replicates the issue, as I requested in my previous reply,

    Colin

This discussion has been closed.