Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all 82246 articles
Browse latest View live

Internalization JSON file doesn't load if I add header to each AJAX request

$
0
0

Hello,
I'm adding a header to each AJAX request like this:

$.ajaxSetup({
    headers: {
         'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
    }
});

But doing so, I'm not able to load the internalization JSON file for my language (https://cdn.datatables.net/plug-ins/1.10.16/i18n/Italian.json), getting this error:

Failed to load https://cdn.datatables.net/plug-ins/1.10.16/i18n/Italian.json: Request header field X-CSRF-TOKEN is not allowed by Access-Control-Allow-Headers in preflight response.

Any idea about how to solve this, keeping the CDN file? Or am I forced to swap to a local internalization file?
Thank you


Row grouping (or sub-rows)

$
0
0

Hi, I've seen the example regarding row grouping here: https://datatables.net/examples/advanced_init/row_grouping.html . Is it possible to group some rows under a disclosure icon to open them up and reveal the rows underneath, such as for rows that are different locations of the same business? Trying to show an example just using text.

    Jim's Canteens   102 Burned Ln      Phoenix AZ      Manager: Jim Jones          6025551123

- Starbucks (multiple matches)
    Starbucks       1108 Welldone Rd    Phoenix AZ      Manager: Mike Williams      6025551212
    Starbucks       1060 Anyplace Ave   Tempe AZ        Manager: Fred Thomas        4805551212

I've also seen the example of sub-rows for additional details: https://datatables.net/examples/api/row_details.html. It seems like I almost am looking for something which combines these two features. :)

Exclude columns from ajax.reload

$
0
0

Hi all, first of all I want to tell that I really enjoy using Datatables. Especially because there is a lot of documentation available. However I can't seem to find how to exclude columns from refreshing with ajax reload.

The situation is as follows, I have a table with a lot of columns that remain unchanged, only a couple columns need continuous refreshing, now I use ajax reload to reload the whole table every 10s. This creates a lot of bandwith. So I was wondering if there is any way that I can put these unchanged columns just in plain HTML and only use ajax reload to refresh those couple columns that need it?

Print button only prints 1 page

$
0
0

Hello guys

I just tried out the button plugin, but when i use the print button print preview only shows 1/1 page, tho there should be more pages.
(only some of the rows comes on)

How can i search for text in parent and child nodes in tree structure table?

$
0
0




my search code is:

var oTableQuery = $('#queriesTable').dataTable({"paging": true,"searching": true,
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] },
{ "width": "2%", "targets": 0 }
],
"aaSorting": [[1, 'asc']] //asc
});

it is only searching at parent level as in image 2. but i am unable to search child level.
Please let me know how can i improve my search ?

Event column-reorder behavior issue.

$
0
0

An issue with column-reorder event.

What I am trying to obtain, is to know if the original column order has been changed. To achieve this, I am using the column-reorder event, and especially the details.mapping parameter.

I was assuming, that if the column order is in the original order, the mapping is a sorted list starting from 0 till the number of columns - 1.

But this appears not to be. So maybe I am missing something.

Here the steps I have done:

Changed columns 2 and 3

details.from shows 2 and details.to shows 3 which is, in my opinion correct.
details.mapping shows 0,1,3,2,4,5,6,7,8,9,10,11,12,13,14,15,16 and this also seems correct.

But then, if I change columns 3 and 2 (so the original situation is back)

details.from shows 3 and details.to shows 2 (correct), but
details.mapping shows 0,1,3,2,4,5,6,7,8,9,10,11,12,13,14,15,16 which is not representing the actual situation.

My 2 questions are:

  1. how can I check if the original column order of a table has been changed?
  2. is the behavior of the column-reorder correct, in respect to the value of details.mapping?

Retain textbox value after pagination

$
0
0

Hi,

I have a problem about datatable pagination. I put textboxes into my datatable. It shows number of records to user by user's choice, for example 5,10,15 records. When I choose 5, some of records are shown in second page.

In this case, I entered some values to textboxes in first page. But when I go to second page and then go back to first page, textbox values are being lost. How can I keep this values after pagination in textboxes?

Thanks.

Any idea how to hide/show columns in editor

$
0
0

Any idea how to hide/show columns in editor, where colvisgroup is not working in editor


How to Export Checked Row (I m using checkbox to select rows)?

$
0
0

1.Server side code

   while( $row=mysqli_fetch_array($queryRecords) ) 
        {  
                     $nestedData=array();
                      $nestedData[] = "<input type='checkbox' onclick='checkboxfn($(this));' id='singleBox'  value='". $index."'  />" ;
                      $nestedData[]  = "<i class='mdi mdi-format-list-bulleted'></i>";
                      $nestedData[]  = $index;
                      $nestedData[] = $row["Designation"];
                      $nestedData[] = $row["CompanyName"];
                      $nestedData[] = $row["PersonalEmail"];
                      $nestedData[] = $row["PersonalPhone"];
                      $nestedData[] = $row["PersonalMobile"];
                     $data[] = $nestedData;
                  $index++;
         }  

$json_data = array(
                          "draw"                => 1,   
                          "recordsTotal"    => intval( $totalRecords ),  
                            "recordsFiltered" => intval($totalRecords),
                           "data"            => $data   // total data array
                        );
   echo json_encode($json_data);  // send data as json format
  1. My Button Code
       dom: 'lBfrtip',
       buttons: [
            {
                extend: 'copyHtml5',
                
                exportOptions: {
                    columns: [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 ]
                }
            },
            {
                extend: 'excelHtml5',
                text: 'XLS',
                exportOptions: {
                    columns: [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
                }
            },
            {
            extend:  'csvHtml5',
            exportOptions: 
            {
                columns: [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
            }
            },
            {
                extend: 'pdfHtml5',
                orientation: 'landscape',//landscape give you more space
            pageSize: 'A0',//A0 is the largest A5 smallest(A0,A1,A2,A3,legal,A4,A5,letter))
                exportOptions: {
                    columns: [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
                }
            },
            
       ], 
                 columnDefs: [{
                "targets": 5,
                "orderable": true
            }]

Column filter in IE 11

Nested Datatables, Child Rows

$
0
0

Hello everyone, I'm having a problem with the nested datatables, the child rows are showing all the data, but I want each information to stay in its particular parent row, can any one help me? my code below...

var oInnerTable;

$(document).ready(function() {
    TableHtml = $('#example').html();
    var table = $('#example').DataTable({
        "bProcessing": true,
        "ajax": {
            "url": 'forms/customer-details/jsonData.php',
            "type": 'POST',
            "data": {
                "idCustomer": <?php echo $idCustomer; ?>
            }
        },
        "scrollX": true,
        "language": {
            "sUrl": "../plugins/datatables/Portuguese-Brasil.json"
        },
        "aLengthMenu": [[10, 20, 30, 50, -1], [10, 20, 30, 50, "Todos"]],
        "aoColumns": [
            {
                "class": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": ''
            },
            {"mData": "NOTA"},
            {"mData": "NRO_NOTA"},
            {"mData": "EMISSAO",
                render: function(data, type, row) {
                    var dateSplit = data.split('-');
                    return type === "display" || type === "filter" ?
                            dateSplit[1] + '/' + dateSplit[2] + '/' + dateSplit[0] :
                            data;
                }
            },
            {"mData": "QUANTIDADE1",
                render: $.fn.dataTable.render.number()},
            {"mData": "BRUTO",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "VALOR_DESCONTO1",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "TOTAL1",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "VALOR_IPI1",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "VALOR_SUBST",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "TOTAL_NF",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "PRECO_MEDIO",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "REPRES_NOME"},
            {"mData": "VENDEDOR_NOME"},
            {"mData": "OP_NOME"},
            {"mData": "FRANQUEADO_NOME"},
            {"mData": "CARTEIRA"},
            {"mData": "TRANSP_NOME"},
            {"mData": "RASTREAMENTO_CORREIO"},
            {"mData": "CONHECIMENTO"},
            {"mData": "VALOR_FRETE",
                render: $.fn.dataTable.render.number('.', ',', 2, 'R$ ')},
            {"mData": "PERCENTUAL",
                render: $.fn.dataTable.render.number('.', ',', 2, '% ')},
            {"mData": "DESCRICAO"},
            {"mData": "DATA_OCORRENCIA"}
        ],
        "order": [[1, "desc"]]
    });

    var table = $('#example').DataTable();
    $('#example tbody').on('click', 'td.details-control', function() {
        var tr = $(this).closest('tr');
        var row = table.row(tr);
        if (row.child.isShown()) {
            row.child.hide();
            tr.removeClass('shown');
        } else {
            row.child(format()).show();
            tr.addClass('shown');
            oInnerTable = $('#detalhes').DataTable({
                "bProcessing": true,
                "ajax": {
                    "url": 'forms/customer-details/jsonNota.php',
                    "type": 'POST',
                    "data": {
                        "idCustomer": <?php echo $idCustomer; ?>
                    }
                },
                "language": {
                    "sUrl": "../plugins/datatables/Portuguese-Brasil.json"
                },
                "aLengthMenu": [[10, 20, 30, 50, -1], [10, 20, 30, 50, "Todos"]],
                "aoColumns": [
                    {"mData": "NOTA"},
                    {"mData": "COD_PRODUTO"},
                    {"mData": "DESC_PROD"},
                    {"mData": "QUANTIDADE"},
                    {"mData": "UNITARIO"},
                    {"mData": "PCT_IPI"},
                    {"mData": "VALOR_IPI"},
                    {"mData": "DESCONTO"},
                    {"mData": "VALOR_DESCONTO"},
                    {"mData": "DESC_UNITARIO"},
                    {"mData": "TOTAL"}
                ],
                "order": [[0, "desc"], [1, "asc"]]
            });
        }
    });
});

How can send parameterized request to the server

$
0
0

im using datatable and im calling an api that return a json object contain 100 record an the total number of all record and the number of pages,when i make a request it only bring me the first page that contains 100 records, how can i request the server to give me the rest of records when i change to the next page!!!

Regex in column search not working

$
0
0

Hi!

I try the following Regex to filter multiple values in a single column:

$datatable.columns( 3 ).search('Samsung S9|Samsung S8',true, false).draw();

In the example https://datatables.net/examples/api/regex.html I get the pipe operator working, why not in my example?
When I remove "|Samsung S8" the columns get nicely filtered on "Samsung S9".

Is there a complete overview of all available data-* attributes?

$
0
0

I'm specifically wondering about a data- attribute for FixedColumns, but as I was searching for that I realised I couldn't find a consise overview of any data- attributes. I did find a list of all options here, but I can't find how they are mapped to data-attributes.

How to fully show colVis modal when datatable is empty?

$
0
0

Hello everyone,
I´m new using datatbles, I have the following one: https://debug.datatables.net/ovinuc. My problem is that when the table is empty the colVis modal doesn´t shows all the colums, just a part, I have another datatable but using version 1.9 and there the ColVis works just fine. Any ideas what this could be?

Thanks in advance


Cannot convert undefined or null to object at Function.keys when POST datatable editor

$
0
0

Hi,
I have done the installation of datatable editor on node.js server.
The datatable editor is populated properly (data in...).
I would assume that GET request of api/staff works perfectly but when I try to do an update/edit/delete the POST request is pending and I receive the following error on the server side:

UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Editor.<anonymous> (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.ts:1328:23)
at step (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:42:23)
at Object.next (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:23:53)
at /root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:17:71
at new Promise (<anonymous>)
at __awaiter (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:13:12)
at Editor._process (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:1072:16)
at /root/myapp/node_modules/datatables.net-editor-server/dist/editor.ts:664:16
at step (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:42:23)
at Object.next (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:23:53)
at /root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:17:71
at new Promise (<anonymous>)
at __awaiter (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:13:12)
at run (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.js:395:36)
at Editor.<anonymous> (/root/myapp/node_modules/datatables.net-editor-server/dist/editor.ts:676:10)
(node:15953) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 12)

Would you be able to help?
Many thanks.

RB

Searching and sorting doesn't work

$
0
0

Hello,

Im using datatables with server side loading via pipelining but I want searching + sorting to work. This does nothing unfortunately.
I get correct json back from the server which is loaded when I open the page with the table but when I want to use the sorting or searching functions it loads for a little second but does not update the table.

    var table = $('#table_id').DataTable({
        serverSide: true,
        "processing": true,
        "language": {
            processing: '<svg class="circular" viewBox="25 25 50 50"><circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /></svg>'
        },
        stateSave: true,
        responsive: true,
        dom: 'Bfrtip',
        lengthMenu: [
            [ 5, 10, 15 ],
            [ '10 rows', '25 rows', '50 rows' ]
        ],
        buttons: [
            { 
                extend: 'pageLength'
            },
            {
                text: 'Selecteer velden', extend: 'colvis'
            }
        ],
        ajax: $.fn.dataTable.pipeline( {
            url: "{{route('pagination1')}}",
            dataSrc : "data"
        }),
        "columns": [
            { "data": "ItemCode"},
            { "data": "Created" },
            { "data": "Description"},
            { "data": "PlannedQuantity"},
            { "data": "PlannedDate"},
            { "data": "Materiaal"},
        ]
    }); 

The pipeline code:

$.fn.dataTable.pipeline = function (opts) {
    // Configuration options
    var conf = $.extend({
        pages: 5, // number of pages to cache
        url: '', // script url
        data: null, // function or object with parameters to send to the server matching how `ajax.data` works in DataTables
        method: 'GET' // Ajax HTTP method
    }, opts);

    // Private variables for storing the cache
    var cacheLower = -1;
    var cacheUpper = null;
    var cacheLastRequest = null;
    var cacheLastJson = null;

    return function (request, drawCallback, settings) {
        var ajax = false;
        var requestStart = request.start;
        var drawStart = request.start;
        var requestLength = request.length;
        var requestEnd = requestStart + requestLength;

        // console.log(request);
        // if (request.search['value'] == "") {
        //     if (request.order[0]) {
        //         var table = $('#table_id').DataTable();
        //         table
        //             .order( [[ 1, 'asc' ]] )
        //             .draw( );
        //         console.log(request.order[0]['column']);
        //         console.log(request.order[0]['dir']);
        //     }
        // }

        if (settings.clearCache) {
            // API requested that the cache be cleared
            ajax = true;
            settings.clearCache = false;
        } else if (cacheLower < 0 || requestStart < cacheLower || requestEnd > cacheUpper) {
            // outside cached data - need to make a request
            ajax = true;
        } else if (JSON.stringify(request.order) !== JSON.stringify(cacheLastRequest.order) || JSON.stringify(request.columns) !== JSON.stringify(cacheLastRequest.columns) || JSON.stringify(request.search) !== JSON.stringify(cacheLastRequest.search)) {
            // properties changed (ordering, columns, searching)
            ajax = true;
        }

        // Store the request for checking next time around
        cacheLastRequest = $.extend(true, {}, request);

        if (ajax) {
            // Need data from the server
            if (requestStart < cacheLower) {
                requestStart = requestStart - requestLength * (conf.pages - 1);

                if (requestStart < 0) {
                    requestStart = 0;
                }
            }

            cacheLower = requestStart;
            cacheUpper = requestStart + requestLength * conf.pages;

            request.start = requestStart;
            request.length = requestLength * conf.pages;

            // Provide the same `data` options as DataTables.
            if ($.isFunction(conf.data)) {
                // As a function it is executed with the data object as an arg
                // for manipulation. If an object is returned, it is used as the
                // data object to submit
                var d = conf.data(request);
                if (d) {
                    $.extend(request, d);
                }
            } else if ($.isPlainObject(conf.data)) {
                // As an object, the data given extends the default
                $.extend(request, conf.data);
            }

            settings.jqXHR = $.ajax({
                "type": conf.method,
                "url": conf.url,
                "data": request,
                "dataType": "json",
                "cache": false,
                "success": function success(json) {
                    cacheLastJson = $.extend(true, {}, json);
                    var data = json['data'];
                    
                    for (var i = 0, leng = data.length; i < leng; i++) {
                        var material = data[i].ShopOrderMaterialPlans['results'];

                        for (var x = 0, len = material.length; x < len; x++) {
                            // console.log(material.length + " " + x);
                            if (getMaterial(material[x]['ItemCode'], 'TAP')) {
                                data[i]['Materiaal'] = material[x]['ItemCode'];
                            }
                        }
                    }

                    if (cacheLower != drawStart) {
                        json.data.splice(0, drawStart - cacheLower);
                    }
                    if (requestLength >= -1) {
                        json.data.splice(requestLength, json.data.length);
                    }

                    drawCallback(json);
                }
            });
        } else {
            json = $.extend(true, {}, cacheLastJson);
            var data = json['data'];

            for (var i = 0, leng = data.length; i < leng; i++) {
                var material = data[i].ShopOrderMaterialPlans['results'];

                for (var x = 0, len = material.length; x < len; x++) {
                    // console.log(material.length + " " + x);
                    if (getMaterial(material[x]['ItemCode'], 'TAP')) {
                        data[i]['Materiaal'] = material[x]['ItemCode'];
                    }
                }
            }

            json.draw = request.draw; // Update the echo for each response
            json.data.splice(0, requestStart - cacheLower);
            json.data.splice(requestLength, json.data.length);

            drawCallback(json);
        }
    };
};

// Register an API method that will empty the pipelined data, forcing an Ajax
// fetch on the next draw (i.e. `table.clearPipeline().draw()`)
$.fn.dataTable.Api.register('clearPipeline()', function () {
    return this.iterator('table', function (settings) {
        settings.clearCache = true;
    });
});

function getMaterial(data, search) {
    if (data && search) {
        if (data.substr(0, 3) === search) {
            return true;
        } else {
            return false;
        }
    }
}

autoComplete.js compatibility?

$
0
0

Hello,

when using autoComplete to Edit an entry of my database with DataTables I receive the javascript error message

Uncaught TypeError: this.source is not a function

with several references to jquery ui. Alas, when I enter a new entry to my database all works surprisingly well. I suspect that the version of autoComplete isn't compatible with the javascript libraries I use. I use one of the last DataTables bundles including

DataTables 1.10.16
jQuery 3.2.1
jquery ui 1.12.1 custom

Could you please tell me which version of autoComplete.js fits best to this configuration?

Thanks,
Eberhard

Fixed Row Count

$
0
0

I'm using datatables with server side processing and I'm trying to figure out how to get datatables to always show a set number of rows. I don't want it to resize vertically when there are less records to display than the set pageLength. If there are only 6 rows to display but the pagelength is 10 then there should be 4 empty rows. If i'm on the last page and there's 2 odd records then there should be 8 empty rows.

I've tried at the server end to add empty rows so it would always return a multiple of 10 (my pagelength) but this creates an issue with sorting and sizing which i may continue to work through but there must be a simple api i can manipulate to set this.

I also found an outdated post (https://datatables.net/forums/discussion/5970/fixed-row-count) on the forum describing how to do this but it looks like the example was cut half way through. There's also mention of an older post giving this information but i can't find it.

Problem Firefox with $.ajax

$
0
0

I have a Problem with a button code.

dtButtons.push( {
 text: '<i class="fas fa-user-plus fa-fw"></i>',
 titleAttr: 'List of all athletes who can participate in this event',
 className: 'text-green',
 action: function( e, dt, node, config ) {
   var data = mt_ls.row( { selected: true } ).data();
   var meetType = ( 'INVITATION' == data.contentType ) ? 'i' : ( ( 'ENTRIES' == data.contentType ) ? 'e' : 'r' );
   $.post( '/lib/adm/setvar.php', { mid: data.DT_RowId, cot: meetType, cid: cID, back: 'mtlst' } );
   location.assign( '/index.php?mo=listE&me=lsath' );
},
enabled: false
} );

The $.post code would not be execute with the FireFox. Have anyone a idea what is wrong here. With Edge and Chrome work
the Code.

Andreas

Viewing all 82246 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>