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

Inline Editing for certain fields only

$
0
0

I have a table with inline editing. I can edit the field ok, but to save each change, i have to click off the datatable. If I select the datatable, I get a error:

uncaught exception: Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11

I assume the issue is that only certain fields can be edited onclick. BUt my onlick code is this:

$('#myTable').on( 'click', 'tbody td:not(:first-child)', function (e) {
editorSignIn.inline( this, {
onBlur: 'submit'
} );
} );

How can I change it so only certain fields are onClick

thanks


how to get value from array columns data on Datatable to variable on php

$
0
0

how get value data to variabel test in php?

{
            'data': 'KPNO_TRANSAKSI',
            'className': "center",
            'render': function (data){
              '<?php $test ?>' = data; // i want get value data to variabel test
              return '<?php echo $test ?>';
            }
          }                 
      ]
    });

Uncaught Error: [$injector:modulerr] in datatables

$
0
0

While injecting datatables and datatables.buttons in angular.module like this
angular.module('myApp',['datatables', 'datatables.buttons']) I get Uncaught Error: [$injector:modulerr] in console
I do not see any other error and I have added all dependencies in my vendor folder and copied on to master.dust which is the common html template for all html files
My code is as below

angular.module('myApp',['datatables', 'datatables.buttons'])
.controller('ViewCtrl', function ($scope, $state, $filter, sharedServices, DTOptionsBuilder, DTColumnBuilder, DTColumnDefBuilder, $q, $stateParams, $sce, $interval, $uibModal) {
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withPaginationType('full_numbers')
.withDisplayLength(2)
.withDOM('pitrfl')
.withButtons([{
extend: 'excelHtml5',
}
]);

And the dependencies are:

<script src="{context.links.resourceBaseUrl|s}/vendor/datatables/js/jquery.dataTables.js"></script>
<script src="{context.links.resourceBaseUrl|s}/vendor/datatables/js/jquery.dataTables.min.js"></script>
<script src="{context.links.resourceBaseUrl|s}/vendor/datatables.net-bs/dataTables.bootstrap.js"></script>
<script src="{context.links.resourceBaseUrl|s}/vendor/datatables.net-bs/dataTables.bootstrap.min.js"></script>


<script src="{context.links.resourceBaseUrl|s}/vendor/datatables/angular-datatables/angular-datatables.min.js"></script>
<script src="{context.links.resourceBaseUrl|s}/vendor/datatables-responsive/dataTables.responsive.js"></script>
<script href="{context.links.resourceBaseUrl|s}/vendor/angular/angular.js"></script>
<script href="{context.links.resourceBaseUrl|s}/vendor/datatables/angular-datatables/angular-datatables.min.js"></script> 

<script href="{context.links.resourceBaseUrl|s}/vendor/datatables.net-buttons/dataTables.buttons.min.js"></script>

<script href="{context.links.resourceBaseUrl|s}/vendor/datatables.net-buttons/buttons.colVis.min.js"></script>
<script href="{context.links.resourceBaseUrl|s}/vendor/datatables.net-buttons/buttons.flash.min.js"></script>
<script href="{context.links.resourceBaseUrl|s}/vendor/jszip/jszip.min.js"></script>
<script href="{context.links.resourceBaseUrl|s}/vendor/datatables.net-buttons/buttons.html5.min.js"></script>
<script href="{context.links.resourceBaseUrl|s}/vendor/datatables.net-buttons/buttons.print.min.js"></script>
<script href="{context.links.resourceBaseUrl|s}/vendor/datatables/angular-datatables/plugins/buttons/angular-datatables.buttons.min.js"></script>

Kindly help

Print option in jquery datatable--would like to print the final total of a column in the footer

$
0
0

Currently only the first page total is printed in the footer.
code used
footer:true,
exportOptions: {

                           modifier: {
                               order: 'index', // 'current', 'applied','index', 'original'
                               page: 'all', // 'all', 'current'
                               search: 'none' // 'none', 'applied', 'removed'
                           },
                           columns: [0, 1, 2, 3, 4]

}
footer call back is

                footerCallback: function( tfoot, data, start, end, display ) {
                    var api = this.api();
                    var intVal = function (i) {
                        return typeof i === 'string' ?
                            i.replace(/[\$,]/g, '') * 1 :
                            typeof i === 'number' ?
                            i : 0;
                    };
                    total = api
           .column(4)
           .data()
           .reduce(function (a, b) {
               return intVal(a) + intVal(b);
           }, 0)

                    pageTotal = api
           .column(4, { page: 'current' })
           .data()
           .reduce(function (a, b) {
               return intVal(a) + intVal(b);
           }, 0);

                    $(api.column(4).footer()).html(
                             pageTotal + ' (' + total + ' total)'
                       );

}

the values displayed in the page are correct. But on print option only the first page total is displayed in the footer.

Datatable ServerSide "SECOND" TD Click Get Detail Poppup

$
0
0

no problem trying responsive feature available datatable. but ı want when I click on the second td I want full detail modal poppup to open there viewable. This feature should not affect the functionality responsive +.

Note: https://datatables.net/extensions/responsive/examples/display-types/modal.html
+ icon is disabled when I use this feature ı don't want it. I want to use the existing + icon feature and I want to open poppup detail when second td is clicked

var assetListVM;
$(function () {
    assetListVM = {
        dt: null,
        init: function () {
            window.$('.js-example-basic-multiple2').select2({
                placeholder: "Tür ...",
                allowClear: true
            });
            window.$('.js-example-basic-multiple3').select2({
                placeholder: "Durum ...",
                allowClear: true
            });
            window.$('.js-example-basic-multiple4').select2({
                placeholder: "Proje ...",
                allowClear: true
            });
            window.dt = window.$('#datatable').DataTable({
                "proccessing": true,
                "serverSide": true,
                "ajax": {
                    "url": '/Teklif/Get',
                    "data": function (data) {
                        if (startDate !== null || endDate !== null) {
                            data.startDate = window.$('#startDate').val();
                            data.endDate = window.$('#endDate').val();
                        }
                        if (window.DurId !== null) {
                            data.DurIds = window.$('#DurId').val().toString();
                        }
                        if (window.TurId !== null) {
                            data.TurIds = window.$('#TurId').val().toString();
                        }
                        if (window.ProId !== null) {
                            data.ProIds = window.$('#ProId').val().toString();
                        }
                    }
                },
                "columns": [
                    { "title": "Sıra", "data": "Id" },
                    { "title": "Tarih", "data": "Tarih", "searchable": true },
                    { "title": "Proje", "data": "ProjeID", "searchable": true },
                    { "title": "Tür", "data": "TurID", "searchable": true },
                    { "title": "Ad", "data": "Ad", "searchable": true },
                    { "title": "Belge No", "data": "DokumanNo", "searchable": true, "stitle:": "DokumanNo" },
                    { "title": "Firma", "data": "CariID", "searchable": true },
                    { "title": "Yetkili", "data": "Yetkili", "searchable": true },
                    { "title": "Telefon", "data": "Telefon", "searchable": true },
                    { "title": "Açıklama", "data": "Aciklama", "searchable": true },
                    { "title": "Oluşturan", "data": "KulID", "searchable": true },
                    { "title": "Durum", "data": "DurumID", "searchable": true },
                    {
                        "title": "KDV Hariç :",
                        "data": "Toplam",
                        "searchable": true
                    },
                    {
                        "title": "KDV Dahil :",
                        "data": "GenelToplam",
                        "searchable": true
                    },
                    {
                        "title": "Eylemler",
                        "render": function (data, type, row) {
                            const inner = `<a href="/Teklif/Güncelle?id=${
                                row.Id}" class="on-default edit-row" title="Güncelle" data-id="${row.Id
                                }"><i class="fa fa-pencil"></i></a> <a href="javascript:void(0);" class="chng-status" title="Teklif Durum" data-id="${row.Id
                                }"><i class="fa fa-circle-o-notch" style="color:crimson;"></i></a> <a href="javascript:void(0);" class="delete-btn" title="Sil" data-id="${row.Id
                                }"><i class="fa fa-trash-o"></i></a>`;
                            return inner;
                        }
                    },
                    {
                        "title": "Revize",
                        "render": function (data, type, row) {
                            const inner = `<a href="/Teklif/GüncelleRevize?id=${
                                row.Id}" class="on-default edit-row" title="Güncelle" data-id="${row.Id
                                }"><i class="fa fa-copy"></i></a> <a href="javascript:void(0);" class="view-revision" data-id="${row.Id
                                }"><i class="ft-list"></i></a>`;
                            return inner;
                        }
                    },
                    {
                        "title": "Dosya",
                        "render": function (data, type, row) {
                            const inner = `<a href="#" class="on-default showfile-btn" title="Teklif" data-id="${row.Id
                                }"><i class="fa fa-file" style="color:red;"></i></a> <a href="#" class="on-default showfile-btn2" title="Arge" data-id="${row.Id
                                }"><i class="fa fa-file" style="color:darkcyan;"></i></a>`;
                            return inner;
                        }
                    }
                ],
                "createdRow": function (row) {
                    window.$.each(window.$('td', row), function () {
                        window.$(this).attr('class', "kisa");
                    });
                },
                'columnDefs': [
                    {
                        'targets': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
                        'createdCell': function (td, cellData, rowData, row, col) {
                            window.$(td).attr('title', cellData);
                            if (col === 4) {
                                window.$(td).attr('id', `title-${rowData.Id}`);
                            }
                        }
                    }
                ],
                "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
                "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                    const oSettings = this.fnSettings();
                    window.$("td:first", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1);
                    return nRow;
                },
                responsive: true
            });
        }
    };
    assetListVM.init();
});

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

DATATABLE SERVERSIDE SECOND TD CLİCK GET MODAL POPPUP DETAİLS

$
0
0

I want to use the existing + icon feature and I want to open poppup detail when second td is clicked. Currently responsive works smoothly but the + responsive feature disappears when I activate this feature modal poppup details referance link

Summerizate: I want modal popup details to be displayed when second td is clicked without being affected by responsive feature

var assetListVM; $(function () { assetListVM = { dt: null, init: function () { window.$('.js-example-basic-multiple2').select2({ placeholder: "Tür ...", allowClear: true }); window.$('.js-example-basic-multiple3').select2({ placeholder: "Durum ...", allowClear: true }); window.$('.js-example-basic-multiple4').select2({ placeholder: "Proje ...", allowClear: true }); window.dt = window.$('#datatable').DataTable({ "proccessing": true, "serverSide": true, "ajax": { "url": '/Teklif/Get', "data": function (data) { if (startDate !== null || endDate !== null) { data.startDate = window.$('#startDate').val(); data.endDate = window.$('#endDate').val(); } if (window.DurId !== null) { data.DurIds = window.$('#DurId').val().toString(); } if (window.TurId !== null) { data.TurIds = window.$('#TurId').val().toString(); } if (window.ProId !== null) { data.ProIds = window.$('#ProId').val().toString(); } } }, "columns": [ { "title": "Sıra", "data": "Id" }, { "title": "Tarih", "data": "Tarih", "searchable": true }, { "title": "Proje", "data": "ProjeID", "searchable": true }, { "title": "Tür", "data": "TurID", "searchable": true }, { "title": "Ad", "data": "Ad", "searchable": true }, { "title": "Belge No", "data": "DokumanNo", "searchable": true, "stitle:": "DokumanNo" }, { "title": "Firma", "data": "CariID", "searchable": true }, { "title": "Yetkili", "data": "Yetkili", "searchable": true }, { "title": "Telefon", "data": "Telefon", "searchable": true }, { "title": "Açıklama", "data": "Aciklama", "searchable": true }, { "title": "Oluşturan", "data": "KulID", "searchable": true }, { "title": "Durum", "data": "DurumID", "searchable": true }, { "title": "KDV Hariç :", "data": "Toplam", "searchable": true }, { "title": "KDV Dahil :", "data": "GenelToplam", "searchable": true }, { "title": "Eylemler", "render": function (data, type, row) { const inner =<a href="/Teklif/Güncelle?id=${
row.Id}" class="on-default edit-row" title="Güncelle" data-id="${row.Id
}"><i class="fa fa-pencil"></i></a> <a href="javascript:void(0);" class="chng-status" title="Teklif Durum" data-id="${row.Id
}"><i class="fa fa-circle-o-notch" style="color:crimson;"></i></a> <a href="javascript:void(0);" class="delete-btn" title="Sil" data-id="${row.Id
}"><i class="fa fa-trash-o"></i></a>; return inner; } }, { "title": "Revize", "render": function (data, type, row) { const inner =<a href="/Teklif/GüncelleRevize?id=${
row.Id}" class="on-default edit-row" title="Güncelle" data-id="${row.Id
}"><i class="fa fa-copy"></i></a> <a href="javascript:void(0);" class="view-revision" data-id="${row.Id
}"><i class="ft-list"></i></a>; return inner; } }, { "title": "Dosya", "render": function (data, type, row) { const inner =<a href="#" class="on-default showfile-btn" title="Teklif" data-id="${row.Id
}"><i class="fa fa-file" style="color:red;"></i></a> <a href="#" class="on-default showfile-btn2" title="Arge" data-id="${row.Id
}"><i class="fa fa-file" style="color:darkcyan;"></i></a>; return inner; } } ], "createdRow": function (row) { window.$.each(window.$('td', row), function () { window.$(this).attr('class', "kisa"); }); }, 'columnDefs': [ { 'targets': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 'createdCell': function (td, cellData, rowData, row, col) { window.$(td).attr('title', cellData); if (col === 4) { window.$(td).attr('id',title-${rowData.Id}); } } } ], "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]], "fnRowCallback": function (nRow, aData, iDisplayIndex) { const oSettings = this.fnSettings(); window.$("td:first", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1); return nRow; }, responsive: true }); } }; assetListVM.init(); });

Issues consuming a Jsonresult object?

$
0
0

I have a Jsonresult method which returns a array of objects, the object is a date and float.

I am using a jsonGet method client side to return the data from the server:

$.getJSON(url,
    { price: thePrice, deposit: theDeposit, deliveryDate: theDeliveryDate.toJSON(), loanTerm: theTerm },
    function (json) {
        BindTable(json);
    }
);

When I do the following I get the error "Requested unknown parameter '0' for row 0, column 0."

function BindTable(result) {
    debugger;
    $("#tblSchedule").dataTable({
        "aaData": result,
        "response": true,
        "aaColumns": [
            { "mData": "PaymentDate" },
            { "mData": "PaymentAmount" }
        ]
    });
    $("#tblSchedule").show();
}

Is there issues with the Jsonresult object being used, when I json.stringify the object I get the same error

When I inspect the object at runtime the javascript object it looks like this:

Should I be formatting the object in some way?

Using .Net C#, jQuery, MVC5

ColReorder and Bootstrap modals

$
0
0

I am using quite a few data tables shown in Bootstrap 3 modals that are shown on custom button click.
This does not work with ColReorder enabled. On first click the table isn't loading. On second button click it does. Editor doesn't work at all.
Took me a while to figure out this was caused by colReorder. There was only one error message using Editor that indicated this.
Solution: Disable ColReorder for data tables in Bootstrap modals.


table header width not match table body

$
0
0


i have two datatables in my page. when first tale loading and drawing.the page has not scroll bar.table header caculated a width for header table. then second table loading and drawing. the srocll bar come out. because the table body of first table is auto width, that is fine. but table header is caculated number. so it would meet problem.

Editor Dependent is not Synchronous with Submission

$
0
0

Greetings
I have a count field, I thought of providing calculation in it, so user can put 2+3 to get 5.
I'm using field.dependent for that.
Here is my code
let field = 'item_count'; editor.dependent(field, (val) => { let obj = {values: {}}; try { let r = eval(val); if (r != val) { obj.values[field] = r; } } catch (e) { obj.values[field] = 0; } return obj; });
This works fine, when I put 2+5 and switch to another field, it will directly be 5.
The problem is when I put 2+5 and then click submit button. It seems that the editor send the data with the originial ("2+5") before the depenent funcion finishes.
Is there a way to make all depenedencies resolve and applied before submissionis sent ?

Child Row with database SQL Server

$
0
0

Hello,

I would like to do : https://datatables.net/examples/api/row_details.html

Parent row : Nom - Adresse - CodePostal - Ville - Pays
Children row : Telephone - Telecopie - SiteInternet - SiteSupport

The data is stored in the table name : 'Para_Editeur'

I work with database SQL Server.

  1. How I can add icon "+" on the rows of my table ?
  2. How I search the data of my row parent ?

My script 'editeur.js' (Datatable parent):

/* Formatting function for row details - modify as you need */
function format ( d ) {
    // `d` is the original data object for the row
    return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+   
        '<tr>'+
            '<td>Téléphone :</td>'+
            '<td>'+d.Telephone+'</td>'+
        '</tr>'+
        '<tr>'+
            '<td>Télécopie :</td>'+
            '<td>'+d.Telecopie+'</td>'+
        '</tr>'+
        '<tr>'+
            '<td>Site Internet :</td>'+
            '<td>'+d.SiteInternet+'</td>'+
        '</tr>'+
        '<tr>'+
            '<td>Site Support :</td>'+
            '<td>'+d.SiteSupport+'</td>'+
        '</tr>'+     
    '</table>';
}
 
$(document).ready(function() {
    var table = $('#table_editeur').DataTable( {
        "bProcessing": true,
        "serverSide": true,
        "ajax":{
            url :"./response-displayrow_editeur.php", // json datasource
            type: "post",  // type of method  ,GET/POST/DELETE
            error: function(){
                $("#table_editeur_processing").css("display","none");
              }            
          },        
        "columns": [
            {
                "className":      'details-control',
                "orderable":      false,
                "data":           null,
                "defaultContent": '',
            },
            { "data": "Nom" },
            { "data": "Adresse" },
            { "data": "CodePostal" },
            { "data": "Ville" },
            { "data": "Pays" },
            { "data": "Telephone" },
            { "data": "Telecopie" },
            { "data": "SiteInternet" },
            { "data": "SiteSupport" },
        ],
        "order": [[1, 'asc']]
    } );
     
    // Add event listener for opening and closing details
    $('#table_editeur tbody').on('click', 'td.details-control', function () {        
        var tr = $(this).closest('tr');
        // var tdi = tr.find("i.fa");
        var row = table.row( tr );
 
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            // tr.find('svg').attr('data-icon', 'plus-circle');
            tr.removeClass('shown');            
            // tdi.first().removeClass('fa-minus-square');
            // tdi.first().addClass('fa-plus-square');
        }
        else {
            // Open this row
            row.child( format(row.data()) ).show();
            // row.child(format(tr.data('ACA'), tr.data('ACA'))).show();
            // tr.find('svg').attr('data-icon', 'minus-circle');
            tr.addClass('shown');
            // tdi.first().removeClass('fa-plus-square');
            // tdi.first().addClass('fa-minus-square');
        }
    } );    
} );

My script 'response-displayrow_editeur.php' (Datatable parent):

<?php
    //include connection file
    include_once(".\db_connection.php");
 
    // getting total number records without any search
    $sql = "SELECT dbo.Para_Editeur.Nom,dbo.Para_Editeur.Telephone,dbo.Para_Editeur.Telecopie,dbo.Para_Editeur.SiteInternet,dbo.Para_Editeur.SiteSupport FROM dbo.Para_Editeur";
    $stmt = sqlsrv_query( $conn, $sql);

    if( $stmt === false ) {
        die( print_r( sqlsrv_errors(), true));
        }

    //iterate on results row and create new index array of data
    while( $obj = sqlsrv_fetch_object( $stmt)) {
         $data[] = $obj;
    }   
 
    echo json_encode($json_data);  // send data as json format
 
?>

Thank you for help

Allow forms to submit data in off-paged data

$
0
0

Here is what I am trying to do:
I have a tabular display. I am using the DataTables system purely for its automatic pagination and "Search" feature. I don't have any plugins installed. Just what comes from the main .js and .css files.

Scenario: I am showing a list of active users in a section of the system. Table contains each user's name, email address, title and department. All of these are simple text columns. The very first column of each row [except the header row] in the table is a simple HTML input checkbox. The user checks a set of boxes to select particular users and then clicks a button at the top of the page [let's say "Deactivate users"].

The system has upwards of 200 users (so even at 100 per page, you will get multiple pages). Now, when the user checks the boxes on or off and then moves to different pages, the checkboxes remain checked on/off. BUT! But, when the page is posted, the values from checkboxes that were not on the active page when the form POST happened don't get sent to the server.

So, the question is, what options do I set or configure to let the web browser pick up the states/values of the checkboxes from the table pages that are not currently visible when the form was posted?

Repro as points:
1. Have (say) 20 rows of data
2. Load them onto a simple HTML table, all normal text columns "<td>foo</td>"
3. Add a form and a submit button to post data to some server side script
4. Add a column to the HTML table and set each row to a simple HTML input type="checkbox", set a unique value for each row to be able to identify which row it came from.
5. Run the page, check boxes and submit, ensure that the server side script sees all the checked rows correctly.
6. Attach DataTables to the HTML table without any options (just defaults)
7. Set page size to 10 rows - so now you get 2 pages
8. Check boxes on one page and submit while on that page -- your script will see all the checkboxes from that page.
9. Check boxes on one page, switch to another table page and then submit -- your script will see NOTHING.
10. Now check boxes on page 1 and page 2, move to page 1 and submit - your script will see only data from Page 1.

Help!!

DataTable not inheriting defaults

$
0
0

As far as I can tell my table, #tableAllBrowseProperties, is not inheriting any defaults I've set in $.fn.dataTable.defaults

Snippets:

$.extend($.fn.dataTable.defaults, {
                dom: '<"datatable-scroll"t><"datatable-footer"ip>',
                language: {
                    paginate: {
                        'first': 'First',
                        'last': 'Last',
                        'next': $('html').attr('dir') == 'rtl' ? '&larr;' : '&rarr;',
                        'previous': $('html').attr('dir') == 'rtl' ? '&rarr;' : '&larr;',
                        'pagination': false,
                        'info': false,
                        'searching': false,
                        "lengthChange": false,
                        "columnDefs": [{
                            "targets": ["js-column-reports", "js-column-trade", "js-column-location"],
                            "searchable": false,
                            "orderable": false,
                }],
                        "pageLength": 5
                    }
                },
                //responsive: true


            });

(Some options here aren't relevant to this particular table)

var x = $('#tableAllBrowseProperties').DataTable({
                    colReorder: true,
                    dom: 'Bfrtip',
                    buttons: {
                        buttons: [
                            {
                                extend: 'colvisGroup',
                                text: 'Show my investments',
                                show: [9, 10, 11, 12, 13]
            },
                            {
                                extend: 'colvisGroup',
                                text: 'Hide my investments',
                                hide: [9, 10, 11, 12, 13]
            }
            ],
                        dom: {
                            button: {
                                tag: "button",
                                className: "btn bg-slate bg-slate mr-2"
                            },
                            buttonLiner: {
                                tag: null
                            }
                        }
                    },
                "searching": false
            });

                x.columns([9, 10, 11, 12, 13]).visible(false); x.on('column-visibility.dt', function (e) {
                    x.columns.adjust().draw();
                });

Link to page:

https://webdev.brandnetics.co.uk/cm/assetzexchange/Bootstrap%204/Template/layout_4/LTR/default/full/browse-properties-v2.html

Any help appreciated.

¿Error no capturado al obtener valores de un datatable?

$
0
0

Tengo una consulta y es la siguiente:
Estoy trabajando con datatables y la cuestión es que yo cargo un excel y obtengo sus datos en json para con esos datos llenarlo en un datatable hasta aquí no hay ningún problema, el datatable tiene un checkbox para seleccionar los datos que quieres obtener.Cuando la primera vez que lleno el datatable desde un excel cargado y selecciono los checkbox todo funciona bien, pero cuando selecciono otro excel y se llena el datatable y selecciono el checkbox me bota el error de no capturado

Aquí dejo mi código

        $dt.on('change', 'tbody input', function () {
            var info = table.row($(this).closest('tr')).data();
            info.checked = this.checked;

            /**  NUEVO CÓDIGO */
            /**  Verificar si todos están seleccionados */
            var countSelected = 0
            var countTotal = 0
            table.data().each(function (info) {
                countTotal += 1;
                if (info.checked) {
                    countSelected += 1;
                }
            });

            /** Actualizamos UI según caso */
            if (countSelected === countTotal) {
                $('thead input').prop("checked", true);
                $('thead input').prop("indeterminate", false);
            } else if (countSelected === 0) {
                $('thead input').prop("checked", false);
                $('thead input').prop("indeterminate", false);
            } else {
                $('thead input').prop("checked", false);
                $('thead input').prop("indeterminate", true);
            }
            /** END NUEVO CÓDIGO */

        });

Can I persist the state of check boxes?

$
0
0

I have a check box in each row of my table (which serves as a checklist). And I need to be able to persist the value of each check box. I've tried stateSave, but that doesn't appear to work for check boxes.

My data is in a local JSON file (an array of objects). Is there an easy way to save this state?


How to save inline when you click on a header

$
0
0

I'm using the inline editor, similar to the example page: https://editor.datatables.net/examples/inline-editing/simple.html. You can duplicate the observed behavior using that sample page.
1. Click on a cell to edit.
2. Change the value.
3. Click on a cell header to lose focus.
4. If you click a header that sorts, click it a second time to resort and find the row cell you just tried to change.

What I'm seeing is that when you click a header cell, you lose your change to the editor cell. I first noticed this after adding column filters. I saw where users would make a change to a cell, then click on a column filter just to leave the cell and let their change commit.

I haven't figured out why the cell change doesn't commit just because you click on the header. If you click on the page to lose focus, it works ok. If you click on another cell, it works ok. From what I can tell, it doesn't work if you click on any header/footer.

Adding date range search

$
0
0

I'm using DataTables to facilitate searching on a database-driven table on a client's site. There's a test case here: http://live.datatables.net/buluseni/7/edit

I already have a few modifications to the code to add individual column searching, export functions etc but the client now wants to add a date range search as well. There are two separate date fields ('Completion Date' and 'Date Paid') and I'd like to add "From" and "To" search boxes for both of these, similar to the example here: http://next.plnkr.co/edit/mdeEYoZtnvpfHCdtSxDP?p=preview&preview

Could some kind person help me to add the required code to my existing Javascript? I've added the HTML for the input boxes and have tried quite a few times with the Javascript but keep getting code errors - unfortunately I'm not great with Javascript and tend to suffer from code blindness! :blush:

Inline editing preSubmit event doesn't capture the correct row 'this'

$
0
0

I'm using inline editor of the grid. In the preSubmit event, as documentation shows, I'm trying to grab 'this' to evaluate the data for validation prior to committing it. I've noticed that 'this' doesn't return the correct row of data. It shows the currently focused row instead of the row that was just edited. So if you're on row 1 and make a change and then click on row 2 to lose focus, 'this' returns a reference to row 2. The params do show the correct reference to row 1.

Is there an easier way to get the data from the row that was just changed or a different event that should be used when inline editing?

Leaving data alone

$
0
0

I'm sure this is out there somewhere I'm just not using the right search criteria. If we input something like January 21-23 into a text field (using latest DT & Editor) it converts that to a date. Is there a universal way to tell DT / Editor to treat the data as verbatim and not convert to a date (or an int ... etc.)?

How can I alter the data editor sends to the server prior to the edits being saved to the database?

$
0
0

My table contains basic user names and addresses. I want to capture the submitted "edits" from the client and validate the addresses on the server side using a service from the USPS. The data returned from that service is often different than what was submitted (zip codes are provided in 9-digit format, words like "street" and "lane" are abbreviated, etc.). Within the global validator I can ensure certain rules were followed and, while I can edit the $data array passed to the validate routine, it appears the validator's $data is a copy, so my editing it doesn't affect what is saved to the database (the edit is succesful, but it saved what the user entered, not what I changed in the validator).
Is a global validator the place to do this or is there a better option? I didn't find any examples where the to-be-edited data is altered prior to the actual database update. I am coding in PHP.
Lastly, I'm a hobbyist developer, so I would appreciate your patience if I'm missing something basic.

Here is my validator:

...

->validator( function ( $editor, $action, $data ) {
    if ( $action === Editor::ACTION_EDIT ) {
        $key=array_keys($data['data'])[0];
        $mydata=&$data['data'][$key]['tblcontacts'];
        $first_name=$mydata['first_name'];
        $last_name=$mydata['last_name'];
        $business_name=$mydata['business'];
        $add1=&$mydata['address1'];
        $add2=&$mydata['address2'];
        $city=&$mydata['city'];
        $state=&$mydata['state'];
        $zip=&$mydata['zip'];
        $email=$mydata['email'];
        $phone=&$mydata['phone'];

        $error_message='';
        // address validation routines take arguments by reference and update 
        // those arguments based on USPS response
        $valid=IsValidContactInfo($first_name, $last_name, $business_name, $email, $phone, $error_message);
        $valid = $valid && IsValidAddressInfo($add1, $add2, $city, $state, $zip, $error_message);

        if(! $valid) {
            return $error_message;
        }
    }
} )

...

Viewing all 81902 articles
Browse latest View live