Are you the publisher? Claim or contact us about this channel

Embed this content in your HTML


Report adult content:

click to rate:

Account: (login)

More Channels


Channel Catalog

Channel Description:

Recent Discussions — DataTables forums

older | 1 | .... | 2265 | 2266 | (Page 2267) | 2268 | 2269 | .... | 2326 | newer

    0 0

    Hi all , i try 2 last 2 day implement to datatable to sqlsrv but I failed
    just fisrt
    big problem all sample code for mysql but i m need to mssql server sql server not used limit sql server 2012 after have but my sql server 2008 r2 i try to this sample code return to error if have best working on to for sql server sample code i want to try
    have Server Side Processing sample code i get it connection error :)

    **DataTables warning: table id=DataTables_Table_0 - Ajax error. For more information about this error, please see**

    # DataTable.php

    class DataTable {
      var $database = "test";
      var $host = "";
      var $user = "usertest";
      var $pass = "secret";
      var $conn;
      var $numRows;
      var $baseTest = "test.dbo.";
        public function __construct() {
            $this->connect($this->host, $this->user, $this->pass, $this->database);
        public function connect($_host, $_user, $_password, $_database) {
            $this->conn = mssql_connect($_host, $_user, $_password) or die(mssql_get_last_message());
            mssql_select_db($this->database, $this->conn) or die(mssql_get_last_message());
        function query($sql) {
            mssql_query('SET ANSI_WARNINGS ON', $this->conn) or die(mssql_get_last_message());
            mssql_query('SET ANSI_NULLS ON', $this->conn) or die(mssql_get_last_message());
            $resultQuery = mssql_query($sql, $this->conn) or die(mssql_get_last_message());
            $results = array();
            while ($row = mssql_fetch_array($resultQuery))
                $results[] = $row;
            return $results;
        function numRows($sql) {
            $resultQuery = mssql_query($sql, $this->conn) or die(mssql_get_last_message());
            $result = mssql_num_rows($resultQuery);
            return $result;
      public function getData($params, $table, $columns) {
            $where = $sqlTot = $sqlRec = '';
            if( !empty($params['search']['value']) ) {
                $where = " WHERE";
                $i = 0;
                foreach($columns as $c) {
                    if($i === 0) {
                        $where .= (count($columns) === 1) ? " (" . $c . " LIKE '%" . $params['search']['value'] . "%' " 
                                                          : " ( " . $c . " LIKE '%" . $params['search']['value'] . "%' ";
                    } else {
                        $where .=" OR " . $c . " LIKE '%" . $params['search']['value'] . "%' ";
                $where .= " )";
            $sql = "SELECT * FROM " . $this->baseTest . "[" . $tabla . "]";
            //Total de registros en la tabla
            $totalRecords = $this->numRows(utf8_decode($sql));
            $sqlTot .= $sql;
            $sqlRec = "SELECT TOP " . $params['length'] . " * FROM( SELECT *, ROW_NUMBER() over (ORDER BY "
                    . $columns[$params['order'][0]['column']] . " " 
                    . $params['order'][0]['dir'] . " ) as ct FROM "
                    . $this->baseTest . "[" . $table . "]"
                    . " " . $where . " ) sub WHERE ct > " . $params['start'];
            if(isset($where) && $where != '') {
                $sqlTot .= $where;
            //Registros a mostrar en la tabla
            $dataRecords = $this->query(utf8_decode($sqlRec));
            //Total registros después del filtro
            $totalRecordsFiltered = $this->numRows(utf8_decode($sqlTot));
            $data = array(
                "draw"            => intval($params['draw']),   
                "recordsTotal"    => intval($totalRecords),  
                "recordsFiltered" => intval($totalRecordsFiltered),
                "data"            => $dataRecords
            return $data;

    ## table.html

        <title>DataTables con SQL Server 2008 R2</title>
        <link href="" rel="stylesheet">
        <table class="datatable">
        <script src="" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
        <script type="text/javascript" src=""></script>
        <script type="text/javascript" src="table.js"></script>

    ## table.js

    $dataTable = new DataTable();
    $table = 'test';
    $columns = array( 
        0 => 'id',
        1 => 'nombre'
    $data = $dataTable->getData($_POST, $table, $columns);
    echo json_encode($data);

    0 0
  • 11/25/18--15:35: Reset order/sort by default
  • Hi,

    I would like to reset the order of the columns as started
    I try to use : fnSortNeutral

    But i can't, I don't know why

    `$.extend( $.fn.dataTable.defaults, {

        "dom": '<"top"AfB>rt<"bottom"ip><"clear">',
        "language": {
            "url": "//",
            "decimal": ",",
            "thousands": ".",
            "language": {
                alphabetSearch: {
                    alphabet: '#ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                    infoDisplay: 'Afficher :',
                    infoAll: 'Tous'
        "paging": true,
        "pagingType": "full_numbers",
        "ordering": true,
        "searching": true,
        "info": false,
        "pageLength": 25,
        fixedHeader: {
            header: true,
            footer: true
        buttons: [
                text: 'Ordre par défaut',
                action: function ( e, dt, node, config ) {
    } ); `


    0 0

    Hi All,

    I've been played with the checkbox styling inside of dataTable but with no much success.

    Have anyone changed the style, like size and some other effect for the checkboxes inside of the dataTables?
    Centralize vertically and horizontally?

    For example: I would like to add this style for my checkboxes, but, I'm not sure of the limitations and possibilities when customizing that

    Style sample:

    Thank you very much in advance!


    0 0

    Hi Allan & All,

    My table is on automatic ajax reload every 3 seconds. Selected cell border disappeared though broswer did save it's location. When I use my arrow keys, it got activated to navigation again. But it will disappear again every 3 seconds.

    I turn off the state saving for a reason. I would like to keep (show) the selected cell (only the cell selected; not filter or page) showing after ajax reload.

    What is the syntax I could add to the refreshTable() function?

    File: js/table.YourTableName.js

    var table = $('#cargoes_lr2').DataTable( {

    var timer;
    function refreshTable(){
        timer = setInterval( function(){
            table.ajax.reload( null, false ); // user paging is not reset on reload
        }, 3000 );

    -- end --

    Thank you!

    0 0

    Timestamp FIELD - "created" ( Postgresql )

    In postgresql I have dates in format

    createdDate : "2018-11-01 23:51:33.534" (TIMESTAMP WITHOUT TIME ZONE)

    I would like to retrieve all orders for 2018-11-01.


    public Predicate toPredicate(Root<Parlamentares> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {

    Expression<Timestamp> createdDate = root.get("created").as(Timestamp.class);

    if (dateBegi != null && dateEnd != null) {
    return criteriaBuilder.between(createdDate, dateBegi, dateEnd);
    } else if (dateBegi != null) {
    return criteriaBuilder.greaterThanOrEqualTo(createdDate, dateBegi);
    } else if (dateEnd != null) {
    return criteriaBuilder.lessThanOrEqualTo(createdDate, dateEnd);
    } else {
    return criteriaBuilder.conjunction();

    Everything works fine when i'm using "createdDate DATE column".

    dateBegi : "2018-11-01" comes from daterangepick.

    How to resolve this problem? Any ideia ?

    0 0

    I'm facing exact same issue as discussed in this thread.

    I have both the horizontal and vertical scroll. The last row gets hidden behind the horizontal scroll but the count below shows that included so this kind of confusing for the user to view 1 row lesser than it says. Please advice me on how to approach this issue.

    Im using
    ''' ..."dom" : 'rtiSB',
    "serverSide" : true,
    "processing" : true,
    "scrollY" : 324,
    "scrollX" : true, ... '''
    Also on scrolling say if the first row shows just half of the row still datatable counts it considers it as a full single row. Is there way to do a smooth scroll without showing half row?

    0 0

     $(document).ready(function () {
                            cache: false
                        var gender = null;
    var table = $('#studentTable').DataTable({
                            "bProcessing": true,
                            "bServerSide": true,
                            "sAjaxSource": "studentService.asmx/GetStudents",
                            "fnServerData": function (sSource, aoData, fnCallback) {
                                aoData.push({ "name": "gender", "value": gender });
                                    "dataType": 'json',
                                    "contentType": "application/json; charset=utf-8",
                                    "type": "GET",
                                    "url": sSource,
                                    "data": aoData,
                                    "success": function (msg) {
                                        var json = jQuery.parseJSON(msg.d);
                                    error: function (xhr, textStatus, error) {
                                        if (typeof console == "object") {
                                            console.log(xhr.status + "," + xhr.responseText + "," + textStatus + "," + error);
    "aoColumnDefs": [
                            { "aaSorting": ["desc", "asc"], "aTargets": [0] }
                            "aoColumns": [
                            { "aaSorting": ["desc", "asc"] },
                            , fnDrawCallback: function () {
                                        $('.image-details').bind("click", showDetails);

    0 0

    Hi all together,

    I checked the following example to see how to use multiple tables with the same configuration:

    So far so good - but I feed my table content via AJAX (JSON). This data feed is part of the configuration:
    "ajax": "sql/json.php",

    It is possible to use multiple tables with the same configuration and also feed the table contents with the above mentioned way?
    Maybe I have to say that I'd like to move the multiple tables in a jQueryUI Tabs structure and I'd also like to load the tables contents only when clicked on the jQueryUI tab. I don't know if that will affect the use of multiple tables in datatables, but maybe good to know anyway.

    Thank you for your help!

    0 0

    Hi Everyone,

    I have an issue with my column search via select Inputs. When I enable scrollX, my search fields are under my Header. but I really don't know why. can you guys help me out?
    Here is a test case:

    0 0

    I am trying to use datatable in angular 6 and was able to configure scrolly, but I am having a challenge with scrollx.
    here is my dtoption set up and tables.

    from component.ts
    this.dtOptions = {
    pagingType: 'full_numbers',
    pageLength: 10,
    scrollX: true,
    scrollY: '500',

    from html


    table datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" class="display nowrap" style="width:100%">


    0 0

    Posted in error - sorry.

    0 0

    Dear comunity,

    after i tried the upload example with an additional upload-field, i have an issue in DataTables. The upload progress of both files works fine but after i refresh datatables page i got an issue in console that one of the document file_id's was unknown (uncaught exception: Unknown file id 21 in table files) so the view will return no data.

    What changes do I have to make to get both upload values ​​from the database? I can not use the multiple file upload because once an image and once a PDF must be uploaded. These values ​​must be displayed in separate columns.

    I think that there must be a change in Select statement because now, two values (files_id's) "image" and "document" ​​have to be fetched but i can't figure it out. :neutral:

    regards from germany,


    <table id="example" class="display" width="100%" cellspacing="0">
                    <th>First name</th>
                    <th>Last name</th>
                    <th>Phone #</th>
                    <th>First name</th>
                    <th>Last name</th>
                    <th>Phone #</th>


    var editor; // use a global for the submit and return data rendering in the examples
    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor( {
            ajax: "../php/upload.php",
            table: "#example",
            fields: [ {
                    label: "First name:",
                    name: "first_name"
                }, {
                    label: "Last name:",
                    name: "last_name"
                }, {
                    label: "Phone #:",
                    name: "phone"
                }, {
                    label: "City:",
                    name: "city"
                }, {
                    label: "Image:",
                    name: "image",
                    type: "upload",
                    display: function ( file_id ) {
                        return '<img src="'+editor.file( 'files', file_id ).web_path+'"/>';
                    clearText: "Clear",
                    noImageText: 'No image'
                    label: "Document:",
                    name: "document",
                    "type": "upload",
                    "clearText": "Clear",
                    "noImageText": 'no pdf'
        } );
        var table = $('#example').DataTable( {
            dom: "Bfrtip",
            ajax: "../php/upload.php",
            columns: [
                { data: "first_name" },
                { data: "last_name" },
                { data: "phone" },
                { data: "city" },
                    data: "image",
                    render: function ( file_id ) {
                        return file_id ?
                            '<img src="'+editor.file( 'files', file_id ).web_path+'"/>' :
                    defaultContent: "No image",
                    title: "Image"
                    data: "document",
                    render: function ( file_id ) {
                        return file_id ?
                            '<a href="'+editor.file( 'files', file_id ).web_path+'" target="_blank">PDF</a>' :
                    "defaultContent": "no pdf",
                    "title": "Document"
            select: true,
            buttons: [
                { extend: "create", editor: editor },
                { extend: "edit",   editor: editor },
                { extend: "remove", editor: editor }
        } );
    } );


    // DataTables PHP library
    include( "../../php/DataTables.php" );
    // Alias Editor classes so they are easy to use
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'users' )
            Field::inst( 'first_name' ),
            Field::inst( 'last_name' ),
            Field::inst( 'phone' ),
            Field::inst( 'city' ),
            Field::inst( 'image' )
                ->setFormatter( Format::ifEmpty( null ) )
                ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/image_upload/__ID__.__EXTN__' )
                    ->db( 'files', 'id', array(
                        'filename'    => Upload::DB_FILE_NAME,
                        'filesize'    => Upload::DB_FILE_SIZE,
                        'web_path'    => Upload::DB_WEB_PATH,
                        'system_path' => Upload::DB_SYSTEM_PATH
                    ) )
                    ->validator( Validate::fileSize( 500000, 'Files must be smaller that 500K' ) )
                    ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
            Field::inst( 'document' )
                ->setFormatter( Format::ifEmpty( null ) )
                ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/document_upload/__ID__.__EXTN__' )
                    ->db( 'files', 'id', array(
                        'filename'    => Upload::DB_FILE_NAME,
                        'filesize'    => Upload::DB_FILE_SIZE,
                        'web_path'    => Upload::DB_WEB_PATH,
                        'system_path' => Upload::DB_SYSTEM_PATH
                    ) )
                    ->validator( Validate::fileSize( 52428800, 'Files must be smaller that 50 MB' ) )
                    ->validator( Validate::fileExtensions( array( 'pdf' ), "Please upload an pdf document" ) )
        ->process( $_POST )

    0 0
  • 11/14/18--03:22: Server-side checkbox filter
  • Hello, this is my table with 2 checkboxes:

    I'm trying to filter data in my table with these two checkboxes (will be more checkboxes and date-picker in the future). I'm using the php server_processing php and ssp.class.php. I found some comments about custom filtering in the ssp.class.php file, but there is no example how to do it and there is no example also in the DataTables forum or internet.

    I know that I need to modify the WHERE conditoin in the ssp.class.php when checkbox is selected, but I'm completely lost how to do it. Thank you in advance.

    0 0

    I would like to be able to reset all the values in individual column search inputs at the click on a custom 'Reset' button in the table. Could you suggest me how to obtain this behaviour ? TIA

    0 0
  • 11/26/18--04:51: columns() OR rather than AND
  • I am searching across 2 columns:


    This seems to equate to if column 0 = hello AND column 1 = hello. Is there a way to match if either column 0 OR column 1 instead?

    0 0


    I have date range filters (yadcf). I need to store all in web storage (stateSave: true) apart of those date filters. So when user will use them and than dicided to leave the page and come back later on, I would to clear filters. However, there are old filters values.

    I thought when I will use searchCols function that will overwrite it> However, it doesn't seem to work. Any idea how to restart filters after user come back to this same web page?

    0 0

    Hi All,
    I have recently upgraded my application from DT-1.10.7 to 1.10.18 and now select-all checkbox is not appearing on grids. On analysis i found this is bcoz of select.datatables.css as it has tbody added in selectors(PFA the image of comparison for better clarity). Due to this the checkbox is not appearing on "th" element. Now my question is, is this a bug in latest grid or it was a bug in older grid and how to resolve it? Any help would be appreciated

    0 0
  • 11/21/18--12:21: hide data until searched
  • Hey,

    I'm trying to see if this is possible. I'm looking to provide the data table information, but don't show the user until they selected a filter option and then just show that data filtered.

    As you can see I have a filter tab. In my current setup. I'll have a filter section where the user can select what they want to see. I'd be using something like, but I'll have checkboxes

    0 0

    Hi Allan,

    My website is split into public | private side.

    For public side, I propose to explicitly state the HTML table including data contents, and then apply datatables to that explicit table (like in zero configuration I call this Option 1.

    From my understanding this is the most assured way to get Google to accurately index the contents of public tables.

    The alternative solutions for populating data are to:

    Option 2: Use datatables to import json data held in the same HTML file
    Option 3: Use datatables to import json data obtained via AJAX

    I believe Option 2 and 3 are better suited to private side where Google indexing is not a concern.

    Do you think I am on the right track by using Option 1 for public side?

    Would Option 2 / 3 guarantee indexing on the public side?

    Many thanks and hope you are keeping well :-)


    0 0
  • 11/26/18--06:45: Custom search filter
  • I've added the following code before $(document).ready:

        function( settings, searchData, index, rowData, counter ) {
            return false;

    I don't see any errors in the console log, but it has no affect on the table whatsoever, I was expecting my table to show zero results.

    I can't seem to get $ to do anything at all...

older | 1 | .... | 2265 | 2266 | (Page 2267) | 2268 | 2269 | .... | 2326 | newer