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

Unescape $.fn.dataTable.util.escapeRegex()

$
0
0

Hello,
i need to unescape api's $.fn.dataTable.util.escapeRegex(). I need it to restore state of column filters made with select fields.

I'm doing the select fields with this:

  initComplete: function () {
                    this.api().columns('.select-filter').every(function () {
                        var column = this;
                        var select = $('<select><option value=""></option></select>')
                            .appendTo($(column.footer()).empty())
                            .on('change', function () {
                                var val = $.fn.dataTable.util.escapeRegex(
                                    $(this).val()
                                );
                                column
                                    .search(val ? '^' + val + '$' : '', true, false)
                                    .draw();
                            });
                        column.data().unique().sort().each(function (d, j) {
                            select.append('<option value="' + d + '">' + d + '</option>')
                        });

and restoring state with this:

 var state = table.state.loaded();
            if (state) {
                table.columns().eq(0).each(function (colIdx) {
                    var colSearch = state.columns[colIdx].search;
                   // alert(colSearch.search.slice(1, -1))
                    if (colSearch.search) {
                         $('select', table.column(colIdx).footer()).val(colSearch.search.slice(1, -1));
                    }
                });
                table.draw();
            }

Above code works for me, except situation, when colSearch.search.slice(1, -1) retruns values with special characters. They are with escapes (made by $.fn.dataTable.util.escapeRegex). So i need to do something like unescape this value. Does anyone tried to do that ?

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


Select Last Inserted Row, Table Desc Order

$
0
0

Hi Allan,

I want to select last inserted row on post submit, but no luck.
My table is ordered by tr_in_id DESC

I'm using this code, but it select the 1st tr_in_id
I'm changing to :first, the selection result also same

trReceivingHeadEditor.on('postSubmit', function( e, json, data, action ) {
                trReceivingHeadTable.rows(':last').select()
            });

Please advise, thank you

not applied width option when use column colspan

$
0
0

if your see image, colspan columns have same width

so I want to set each column width.

ex) col 1 : 100px;
col 2 : 150px;
col 3 : 300px;

although I assigned Width, Its ignored

Why would that be??

I set table-layout:fixed; at Table

And My code is below

$('#srTable').DataTable( {
        autoWidth   : true,
        paging      : false,
        scrollY     : 400,
        data : tabData,
        deferRender     : true,
        columns         : [
                            { data      : "taskType",
                              width         : "10px",
                              className     : "dt-center"
                            },
                            { data      : "taskCardNumber",
                              width         : "50px",
                              className     : "dt-center dt-nowrap",
                              createdCell   : function( td, cellData, rowData, row, col){
                                            $(td).attr("title", cellData );
                               }
                            },
                            { data      : "taskTitle",
                              width         : "100px",
                              className     : "dt-body-left dt-nowrap",
                              createdCell   : function( td, cellData, rowData, row, col){
                                            $(td).attr("title", cellData );
                                            $(td).css("//width", "50px" );
                               }
                               } ]
});

how to align scrollable thead and tbody

$
0
0

please reply as soon as possible

How do i Output Two columns from mysql to one data cell

$
0
0

Hi am trying to output two columns from a mysql database to one cell in the datatable. how do i do that am using the server side array in php

__$columns = array(
array( 'db' => 'no', 'dt' => '0' ),
array( 'db' => 'name',  'dt' => '1' ),
array( 'db' => 'phoneno',   'dt' => '2' ),
array( 'db' => 'email',     'dt' => '3' ),

array(
    'db'        => 'idno',
    'dt'        => '4',

),
array(
    'db'        => 'idno',
    'dt'        => '5',

),
array( 'db' => 'clientno', 'dt' => '6', 'formatter' => function( $d, $row ) {
            return '<a href="../clients/add_clients.php?clientid='.$row[6].'"><span class="label label-inverse"><i class="fa fa-edit"></i> Edit</span></a>';},

        'field' => 'clientno' )

);__

how do i change this part of the server side code to asc or desc

$
0
0

i want to change the order of my queries how do i change the below part

$requestData['order'][0]['dir']

Select Value Not Updating

$
0
0

Hi All,

I have the following code and it's almost perfect apart from when a user changes the select value, this doesn't reflect in the database. Everything else updates as it should do, can anyone see where I have gone wrong here?

Thanks

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "../../includes/ajax/load_contracts.php",
        table: "#contract",
        idSrc:  'contract.contractID',
        fields: [ {
                label: "Contract Number:",
                name: "contract.contractNumber"
            }, {
                label: "Contract Start:",
                name: "contract.contractStart"
            }, {
                label: "Contract Term:",
                name: "contract.contractTerm"
            }, {
                label: "Fleet:",
                name: "fleet[].fleetID",
                type: "select"
            }
        ]
    });

    $('#contract').DataTable( {
        dom: "Bfrtip",
        ajax: {
            url: "../../includes/ajax/load_contracts.php",
            type: 'POST'
        },
        columns: [
            { data: "contract.contractID" },
            { data: "contract.contractNumber" },
            { data: "contract.contractStart" },
            { data: "contract.contractTerm" },
            { data: "fleet", render: "[, ].name" }
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );
<?php
  // DataTables PHP library
  include($_SERVER['DOCUMENT_ROOT'] . '/includes/datatables/DataTables.php');

  // Alias Editor classes so they are easy to use
  use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

  // Build our Editor instance and process the data coming from _POST

  Editor::inst( $db, 'contract', 'contract.contractID' )
  ->fields(
    Field::inst( 'contract.contractID' ),
    Field::inst( 'contract.contractNumber' ),
    Field::inst( 'contract.contractStart' ),
    Field::inst( 'contract.contractTerm' )
  )

  ->join(
      Mjoin::inst( 'fleet' )
        ->link( 'contract.contractID', 'contract_customer.contractID' )
        ->link( 'fleet.fleetID', 'contract_customer.customerID' )

        ->fields(
          Field::inst( 'fleetID' )
            ->options( 'fleet', 'fleetID', 'name' ),
          Field::inst( 'name' )
        )
  )
  ->process( $_POST )
  ->json();
?>

fixedHeader Extension not working, no idea why

$
0
0

Hi,

I have a problem with the fixedHeader Extension. I created this http://live.datatables.net/bulekeyi/1/edit example. I have no idea why it isn't working this time. It already worked for me on another site and now it isn't so I am bit confused...

I would appreciate any help.

Thanks in advance


Is there a mailing list for release updates?

$
0
0

I am trying to stay current with DataTables and several plugins. Is there a mailing list to which notifications are sent when releases are updated? If so, how does one get on that list?

Also I notice that Announcements category in the forum doesn't seem up to date. E.g., last announcement for DataTables is 1.10.10, but it seems 1.10.12 is the latest release.

Thanks for all of this -- of all the packages I'm using in my application, I would say this one provides the most benefit to my development.

Editor 1.5.6 // Bug with bootstrap style inline editor ?

$
0
0

Hello all,

I have just upgraded to Editor 1.5.6. i have a strange behaviour with inline editor styling.

When I do inline edit with one of the tables that was working normally with 1.5.5 the stile applied to text edito and to drop dow selector is not styled in accordante with boostrap.

If I select the row and perform a normal modal edit the modal window style is actually boostrap.

When I exit the window and try again on my table inline edit then the boosrtrap style is correctly applied.

Is it a know bug? Did I do anything wrong?

ty
f

unable to destroy datatable created with html5 export buttons

$
0
0

I just want to destroy and reinitialize datatable.

I initialized datatable with following options

dataTableobj = $("#dataTable").dataTable({ "bDestroy": true, "scrollX": true, dom: 'Bfrtip', buttons: ['csv', 'excel', 'pdf'] });

but trying to destroy it with following line

dataTableobj.fnDestroy();

it returns following error in console

TypeError: a[b] is undefined

with following inner details

.destroy()
  dataTables.buttons.min.js:7
 ._constructor/<()
  dataTables.buttons.min.js:10
 m.event.dispatch()
  jquery.min.js:3
 m.event.add/r.handle()
  jquery.min.js:3
 m.event.trigger()
  jquery.min.js:3
 .trigger/<()
  jquery.min.js:3
 .each()
  jquery.min.js:2
 m.prototype.each()
  jquery.min.js:2
 .trigger()
  jquery.min.js:3
 u()
  jquery.dataTables.min.js:75
 <anonymous>
  jquery.dataTables.min.js:137
 .iterator()
  jquery.dataTables.min.js:99
 <anonymous>
  jquery.dataTables.min.js:136
 r.extend/g/<()
  jquery.dataTables.min.js:102
 m/this.fnDestroy()
  jquery.dataTables.min.js:79
 ViewSO/<.success()
  SalesOrderList.aspx:514
 m.Callbacks/j()
  jquery.min.js:2
 m.Callbacks/k.fireWith()
  jquery.min.js:2
 x()
  jquery.min.js:4
 .send/b()

Sorting Percentages with N/A Values

$
0
0

Hi!

So I'm trying to sort columns that have a percentage in them if a calculated number is valid, otherwise they contain the string "N/A". Is there a way to use the percent sorting plug-in as well as some other sorting plug-in to get "N/A" sorting with the rest of the values?

Currently I have the percentage columns being built like this:

{ "sTitle": "YTD I/E Ratio", "sClass": "lossRatio tdright thcenter", "sWidth": "3%", "sType": "percent"}

They are being built in a JavaScript file and I making the call to "//cdn.datatables.net/plug-ins/1.10.12/sorting/percent.js" in my HTML file.

If anyone has further questions about anything that I'm doing, please let me know.

I would like to thank everyone in advance for their help.

Thanks,
Justin

I need some help to pass Json parameter to the datatable

$
0
0

I have the json string returned from the database. The representation is
var myList = [ {
"name" : "abc",
"age" : 50,
"hobby" : "swimming"
}, {
"name" : "pqr",
"age" : 25,
"hobby" : "swimming"
}, {
"name" : "xyz",
"age" : 75,
"hobby" : "programming"
} ];

How do I pass this to the datatables.? I have looked for the Ajax json calls, but the implementation is not working.

Datatable load/Reload based on Selection

$
0
0

Hi ,.

I have a dropdown locations., based on the location the datatable need to be display.

$selLocation.on('change', function(){
$('#example').DataTable( {
"ajax": "data/objects.txt",
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
}

The problem is when I click second time i get the error -- https://datatables.net/manual/tech-notes/3

Can you tell me how can i Initialized the datatable first without even clicking the selection and on selection I can just call
table.ajax.reload(null,false);

how to ignore a specific string or 'N/A' for sorting.

$
0
0

if type is 'percent' and in case of 'N/A' , these row always should appear at the end .

$(document).ready(function() {

$.extend( true, $.fn.dataTable.defaults, {
    "bPaginate":       false, //hide pagination
    "bFilter":         false, //hide Search bar
    "bInfo":           false, // hide showing entries
    "bAutoWidth":      false,
    "fixedColumns":    true
} );

$.extend( jQuery.fn.dataTableExt.oSort, {
    "percent-pre": function ( a ) {
        var x = (a == 0) ? 0 : a.replace( /%/, "" );
        return parseFloat( x );
    },

    "percent-asc": function ( a, b ) {
        if (isNaN(a) && isNaN(b)) return ((a < b) ? 1 : ((a > b) ? -1 : 0));

        if (isNaN(a)) return 1;
        if (isNaN(b)) return -1;

        a = parseFloat( a );
        b = parseFloat( b );
        return parseFloat((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "percent-desc": function ( a, b ) {
        if (isNaN(a) && isNaN(b)) return ((a < b) ? 1 : ((a > b) ? -1 : 0));

        if (isNaN(a)) return 1;
        if (isNaN(b)) return -1;

        a = parseFloat( a );
        b = parseFloat( b );
        return parseFloat((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
} );


$('#HTML-ID').DataTable( {
    "order":           [[ 6, "desc" ]],
    "columnDefs":      [{ type: 'percent', targets: 6 },{ "type": "percent", "targets": 4 }]
} );

} );


Editor not from CDN, but what about the rest of the package / plugins

$
0
0

https://datatables.net/download/index says CDN is not available if Editor is selected. I assume it is possible to download Editor, but get the rest of DataTables and its plugins from the CDN, but would prefer to get confirmation before proceeding.

How can I save the sort state of a table and pass it to another?

$
0
0

I have a table where the user can click on the various columns to sort. I want to save their sort selection and then pass it to another table. For example, if the user sorts table 1 by column A, I want that pass that column A information to another method. I know I can use the statesave option for saving the sort options for a specific table, but I do not know how to pass that information to another object.

Any insight or help would be greatly appreciated.

Save and restore the state of all search boxes

$
0
0

I am using data tables with multiple search boxes, and stateSave enabled. The table will indeed save the state, but when reloading the table, the search boxes do not save.

For example, I have 3 columns... Book Author, Book Title, and Book ISBN. I have a search box for each column for greater searching power. If I search for "Mark" in author, all results with the name Mark in the author appear, as expected. Refreshing the page, or doing any other action which will force the table to reload (such as adding a book), the saved search results appear, but the search box is blank. To get all the items to reappear, I need to go to the book author search box and press backspace.

So... how can I save the state of the searchByAuthor text box?

Or... how can I get the value that was searched for, and what column it was used on? If I can get that, I can repopulate the correct search box.

Server Side Ajax Page navigation(numbers or next button) not working

$
0
0

The first request to the server is working fine, datatable is updated with data correctly. When I click on page navigation(numbers or next button) request is sent corrently to server, and response is returned correctly. The datatable data is not refreshing, and it remains in the first page.

Extract from datatable config..

buttons: ['excel', 'pdf', 'print'],
pagingType : "full_numbers",
processing: true,
serverSide: true,
sServerMethod: "POST",
lengthChange: false,
iDisplayLength: 25,
"ajax": {
"type": "POST",
"url": "url_path",
"data": $("#submittedApplication").serializeObject()

     } ,
     aoColumns: [
              ----------
      ],
     footerCallback: function ( row, data, start, end, display ) {

**My request contains
**
draw:20

columns[0][data]

start:100
length:25
search[value]:
search[regex]:false

Response contains
amount: 25
draw: 20
iTotalDisplayRecords: 1750
iTotalRecords: 1750
message: null
recordsFiltered: 1750
recordsTotal: 1750
sColumns: null
sEcho: "1"
start: 100

I am using same response class(Java) to handle legacy and new datatable so you see iTotalDisplay*** and recordsTotal and recordsFiltered in the response.

Please help!!

sort based on the header title text not the header

$
0
0

Hi I have a question like how to sort by clicking on the name of the column not the header. I tried unbinding TH but it did not worked for me and also tried below code but nothing worked for me. Need help and please suggest me.
$(column.header()).on('click', function(e){
e.stopPropagation();
})

Viewing all 82226 articles
Browse latest View live


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