Link to test case: http://live.datatables.net/fotorewe/19/
Description of problem: How would one reorder the options in the filter? I do not want them to be in alphabetical order. For example, in Office, I want New York to be the first option.
Reorder the column filter integration options
Action/Hook/Event to tap into when SearchBuilder panel opens/closes
I am trying to do a couple of items with the SearchBuilder extension.
1.) When user clicks on button to enable SearchBuilder, I would like to change the text on the button to say CLOSE
2.) Since the SearchBuilder panel is positioned absolutely it is overlapping the actual DataTable, so if the results are just 1 or 2 records they do not get seen until you close the panel.
So if there was an event I could tap into I could easily add/remove margin when that button is presses, and I could easily update the text of the button.
The code I have currently is
(function ($) {
'use strict';
$(function () {
$('.vendor-list').DataTable({
"order": [[0, "asc"]],
"pageLength": 50
});
$('.products-list').DataTable({
pageLength: 50,
lengthMenu: [[5, 15, 25, 50, 100, -1], [5, 15, 25, 50, 100, 'Show all']],
colReorder: true,
dom: '<"#search-pane.hidden"P>' + 'Bfrtip',
language: {
searchBuilder: {
button: {
0: '<i class="fa fa-cog" aria-hidden="true"></i> Advanced',
1: '<i class="fa fa-cog" aria-hidden="true"></i> Advanced (1)',
_: '<i class="fa fa-cog" aria-hidden="true"></i> Advanced (%d)'
},
}
},
buttons: [
{
text: '<i class="fa fa-filter"></i> Filter',
className: 'filter-btn',
action: function (e, dt, node, config) {
$('#search-pane').toggle(100, function(){
var $filterBtn = $('.filter-btn span').html();
if($filterBtn === '<i class="fa fa-filter" aria-hidden="true"></i> Filter'){
$('.filter-btn span').html('Close');
} else {
$('.filter-btn span').html('<i class="fa fa-filter"></i> Filter');
}
});
}
},
{
extend: 'searchBuilder',
text: '<i class="fa fa-cog"></i> Advanced',
className: 'search-builder-btn',
// action: function (e, dt, node, config) {
// console.log('clicked');
// // var $searchBuilderBtn = $('.search-builder-btn span').html();
// // if($searchBuilderBtn === '<i class="fa fa-cog" aria-hidden="true"></i> Search Builder'){
// // $('.search-builder-btn span').html('Close');
// // } else {
// // $('.search-builder-btn span').html('<i class="fa fa-cog"></i> Search Builder');
// // }
// $.fn.dataTable.ext.buttons.searchBuilder.action.call(this, e, dt, node, config);
//
// },
config: {
depthLimit: 2
}
},
{
extend: 'colvis',
text: '<i class="fa fa-eye" title="Toggle Columns"></i> Show/Hide Columns',
className: 'btn btn-secondary',
columns: '.toggle',
postfixButtons: ['colvisRestore']
}, ],
searchPanes:{
show: false,
controls: false,
cascadePanes: true,
hideCount: false,
layout: 'columns-6',
},
columnDefs: [
{
targets: ['hide-column'],
visible: false,
},
{
searchPanes:{
show: true,
},
targets: ['search-pane'],
}
],
});
});
})(jQuery);
Serverside, localStorage, reload ajax withs params
Hi, I have a problem with ajax reload with params. Ajax returns correct data however table does not refresh. I have tested all found solutions and none seems to work. Any help would be appreciated.
xTable = $('#xList').DataTable({
dom: "<'row submenu3'<'col-sm-6'B><'col-sm-4'i><'col-sm-2'p>>" +
"<'row tabtable3'<'col-sm-12'tr>>",
order: [[1, "desc"]],
orderCellsTop: true,
fixedHeader: true,
pageLength: 50,
paging: true,
rowId: "id",
scrollX: true,
scrollY: getheight(140)+'px',
lengthMenu: [[15, 30, -1], [15, 30, "All"]],
serverSide": true,
"ajax": {
"type": "POST",
"url": "all.php",
"data": function ( d ) {
return $.extend( {}, d, {
"token": $('meta[name="token"]').attr("value"),
"start": localStorage.getItem('srv_startdate'),
"end": localStorage.getItem('srv_enddate'),
"filters": localStorage.getItem('srv_filters')
} );
}
},
$('#flDateRange').on('apply.daterangepicker', function(ev, picker) {
$("#xList").DataTable().ajax.reload();
});
Display sum of column instead of counting rows in search pane
Link to test case: http://themeadow.se/ntjperrors/
Debugger code (debug.datatables.net):
Error messages shown: No error messages shown.
Description of problem:
How can I have the counters within the search panels sum by row 11, rather than counting the rows?
I have tried to implement the solution given here but I can't get it to work.
Can I search in SearchBuider by date only in the datetime column?
hello,
I have a datetime column in my database. (mssql server, and the column name is: fa.FA.FELVETEL_IDEJE)
I use searchPane , but it is not interesting now.
server side:
Field::inst( 'fa.FA.FELVETEL_IDEJE' )
->searchPaneOptions( SearchPaneOptions::inst())
->validator( Validate::dateFormat( 'Y-m-d' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
When I try to search using sqlbuilder, I run into the following problem.
When I give it a date, but only the date, the sql filter does not find a result.
So:
fa.FA.FELVETEL_IDEJE = '2022-01-05' then no result, this is all ok (?) , because the records in the datetime column in the database contain the time too!)
fa.FA.FELVETEL_IDEJE
row1: 2021-01-05 11:11:02
row2: 2021-01-05 11:12:03
rown: 2021-01-05 11:13:01
It is therefore understandable (?) that
fa.FA.FELVETEL_IDEJE = '2022-01-05' = no result (as far as I know, if no time is given, sql adds a default time, which in this case is 00:00:00)
but, if I specify it like this:
fa.FA.FELVETEL_IDEJE = '2022-01-05 11:11:02' = 1 result
Question:
How can the time be ignored somehow?
I don't want to split the datetime column into date + time columns
Or,
I tried to use this function on the server side, by reference, but it doesn't work in the function either! (that's why the echo is included, and I'm watching the debug mode of course )
https://editor.datatables.net/manual/php/formatters
(under Custom formatters)
->setFormatter( function ( $val, $data ) {
echo "############";
return $val
? 'Done'
: 'To Do';
return '$val';
} )
best regards
Máté
ColReorder with Keytables (cell.render) does not give the correct value after reordering a column
Hi Everyone,
I have the following problem: For cells of a specific column, i am rendering "Press Enter for details" for type === 'display'. If the user presses enter on a specific cell of this column, i am presenting the data rendered from type === 'export' with cell.render('export'). So this works well as long as the user is not reordering this specific column via Colreorder. After reordering the specific column --> cell.render('export') will just give back "Press Enter for details" - instead of showing the correct data behind cell.render('export'). Do you have solution for that?
Testcase: http://live.datatables.net/pinebici/2/edit
Here the specific column is "Position". When you press enter on a cell of this column you will see the correct value from cell.render('export'). nevertheless after reordering of this column and then pressing enter you will just see "Press Enter for details" within the console.
Bug: Only one Split Button allowed
In case you have more than one split button the dropdown will always display underneath the first of them.
I checked the code: All divs with a split button ("splitDiv") are assigned the same class...
var splitDiv;
if(isSplit) {
splitDiv = $('<div/>').addClass(this.c.dom.splitWrapper.className)
splitDiv.append(button);
var dropButtonConfig = $.extend(config, {
text: this.c.dom.splitDropdown.text,
className: this.c.dom.splitDropdown.className,
closeButton: false,
attr: {
'aria-haspopup': true,
'aria-expanded': false
},
align: this.c.dom.splitDropdown.align,
splitAlignClass: this.c.dom.splitDropdown.splitAlignClass
})
And then the first splitDiv is the node ... That cannot work because the button name is not part of the class name.
return {
conf: config,
node: isSplit ? splitDiv.get(0) : button.get(0),
inserter: isSplit ? splitDiv : inserter,
buttons: [],
inCollection: inCollection,
isSplit: isSplit,
inSplit: inSplit,
collection: null
};
Infinite draw loop when having DT_RowId in ajax response
Hi guys,
ok, this took me 5 hours to find:
http://live.datatables.net/fudifija/1/edit
When having DT_RowId
in the ajax response correctly set (see http://showroom.efficient.it/ajax.php) and using the example code from
https://datatables.net/extensions/searchpanes/examples/customFiltering/customOptionConditions.html, searchPanes crashes into an infinite draw loop.
Just click a checkbox of a row and check the console output.
Greetings,
Pascal
How can I exclude the # rows displayed from State Restore?
We want to allow States to load without changing the # rows displayed.
I thought "paging" would be the setting to turn off but that doesn't work.
Is it possible to disable # rows displayed from a saved state ?
I don't see one on the documentation page https://datatables.net/reference/option/stateRestore.saveState
Collection dropdown is not showing
I am currently a react based based application to display the table and I see no error message. I am currently having an issue creating a test case on sandbox. As one may see, the dropdown is appearing bellow the table. What causes that if I have no styling yet.
export const Table = ({ columns, data, dom, buttons }) => {
console.log(data);
useEffect(() => {
$(window).on('load', function () {
var table = $('#table_id').DataTable({
data: data,
columns: columns,
dom: 'Bftrip',
buttons: [
{
text: '<i class="fa fa-th-list" />',
extend: 'colvis',
dropup: true,
},
{
text: '<i class="fa fa-print" aria-hidden="true"></i>',
extend: 'print',
dropup: true,
},
{
extend: 'collection',
layout: 'fixed',
background: false,
autoClose: true,
fade: 0,
align: 'bottom-right',
text: '<i class="fa fa-download" aria-hidden="true"></i>',
buttons: ['csv', 'excel', 'pdf'],
dropup: true,
},
{
text: '<i class="fa fa-filter" aria-hidden="true"></i>',
extend: 'collection',
action: function (e, dt, node, config) {
alert('Button activated');
},
},
],
});
$('.my_filter').on('click', function () {
var data = table.search('ceda').data();
console.log('The table has ' + data.length + ' records');
});
});
// setLoading(false);
}, []);
return (
<div>
{data && (
<>
<div class="info" style={{ minHeight: 25 }} />
<table
style={{ paddingBottom: 35, paddingTop: 35 }}
id="table_id"
className="display responsive table table-bordered"
></table>
</>
)}
</div>
);
};
Invalid searchPanes options should not be restored from stateSave
Hi guys,
another one to go:
http://live.datatables.net/jexikuxe/2/edit
1) Load the page and select a searchPane filter option
2) Reload the page
-> "No matching records found"
searchPanes options from the previously saved state should not be set if this option is no longer present.
(eg. having a table with dynamically removed rows.)
Greetings,
Pascal
Join Tables and bubble ( Update field )
Hi,
I have a problem with join tables ( Table A and B ).
I need to update only one field from the table B.
I did it with a bubble. It work, when i click on the field the bubble is displaying.
But when i click on update, the field never updated.
Why ?
Regards
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Restrict the first column filter to the first four chars
Hi,
considering this example:
https://datatables.net/examples/api/multi_filter_select.html
I don't know how to restrict the filter string length of the first column only to the first 4 chars...
I saw that the select options menu item is the same for all the column... so i'm wondering if i change the first one the will change also the others...
Any help on this?
columnDefs width Not Working
I have a three-column table on which I'm trying to change the second column's width to 400 pixels. However, my columnDefs is having no effect. I'm wondering why it isn't working? Could it be because I'm loading JSON data or another reason?
Here's my DataTable() call:
$( '#ajax-datatable').DataTable( { ajax:{ url: 'https://example.com/json', dataSrc:'' }, "columns": [ { "data": "id" }, { "data": "status" }, { "data": "permit" } ], scrollX: true, pageLength: 10, pagingType: 'full_numbers',
columnDefs: [
{ targets: [ 1 ], width: '400px' } // <-- Not working.
],
drawCallback: function() {
$( '.dataTables_paginate > .pagination' ).addClass( 'pagination-rounded' );
}
} );
Problem getting the right data from my tables to show (Laravel 7 eloquent models)
Hello, I'm not sure where to post this since I'm new to these forums, so correct me if I posted it wrong.
So as the title says I'm working on a project in Laravel 7 with eloquent models, but I'm having a hard time showing the data that's a couple of tables deeper. Everything has a hasMany or belongsTo relationship with each other so no problems there.
This is how my controller is set up:
My tables are like this: User->consultant->consultantOpportunity->timesheet->workday->dayType. Now I try to show all the workdays from the consultant that's logged in. That's what the orange-marked code is for. This works since I only get the consultant that's logged in to show. But now I need to go deeper. I specified the relationships in the yellow marked code. And as you can see I need to get from Consultant to Workdays which is 3 tables deeper. In the blue marked code, I tried to throw the code in a data tag so I maybe could just split it up with jquery/ajax but it's a little too much as you can see here:.
I commented out the data I wanna get for now since it doesn't work.
but it might give you an idea what I try to achieve. I wanna read out like start hour, end hour, etc. from the Workday table. If I start from the Workday table then I can read all the data out but then it just gives me all workdays in the table and not only from the
consultant logged in. (The consultant needs to be able to register his own worked hours per day)
Idk if there is a simple way to do this? Any help is appreciated. Sorry for my bad English, if you need any additional information let me know and I'll try to explain it better with some extra pictures. Thanks.
Unable to Draw Child/Nested DataTable on Click Button
I am creating dynamic child/nested datatable like below
$( document ).ready(function() {
var oInnerTable;
...........
$('.table_rotators tbody').on('click', 'td.details', function () {
var tr = $(this).closest('tr');
var row = table.row( tr );
var rotator_id = $(this).attr('data-url');
console.log(rotator_id);
if ( row.child.isShown() ) {
row.child.hide();
tr.removeClass('shown');
}
else {
row.child(format(rotator_id)).show();
oInnerTable = $("#url_table_" + rotator_id).dataTable({
"processing": true,
"serverSide": true,
"ajax":{
url :"actions/data_url_response.php",
type: "post",
data: function ( d ) {
d.rotator_id = rotator_id;
}
},
autoWidth: false,
columnDefs: [
{
"targets":[0, 6],
"orderable":false,
},
{
targets: 0,
render: function (data, type, row) {
return '<div class="form-check"><input type="checkbox" class="form-check-input position-static select_ids" value="'+row[0]+'"></div>';
}
}
],
dom: '<"datatable-scroll"t><"datatable-footer"ip>',
language: {
search: '<span>Filter:</span> _INPUT_',
searchPlaceholder: 'Type to search...',
lengthMenu: '<span>Show:</span> _MENU_',
paginate: { 'first': 'First', 'last': 'Last', 'next': $('html').attr('dir') == 'rtl' ? '←' : '→', 'previous': $('html').attr('dir') == 'rtl' ? '→' : '←' }
}
});
tr.addClass('shown');
}
});
function format (d) {
var table ='<div class="card border">' +
'<div class="card-header bg-transparent header-elements-inline">' +
' <form class="form-inline"> ' +
' <div class="form-group-feedback form-group-feedback-right">' +
' <input type="search" id="searchByName" data-id="'+d+'" class="form-control wmin-200 url_search" placeholder="Search...">' +
' <div class="form-control-feedback">' +
' <i class="icon-search4 font-size-base text-muted"></i>' +
' </div>' +
' </div>' +
' ' +
' <div class="form-group ml-3">' +
' ' +
' <select class="form-control wmin-200 url_status" name="url_status" data-id="'+d+'" data-width="100%">' +
' ' +
' <option value="-1">Active URLs</option>' +
' <option value="-1">Paused URLs</option>' +
' <option value="-1">Archived URLs</option>' +
' ' +
' </select>' +
' ' +
' ' +
' </div>' +
' ' +
' </form>' +
' <div class="header-elements">' +
' ' +
' <form class="form-inline"> ' +
' ' +
' <div class="form-group mr-3">' +
' ' +
' <button type="button" data-id="'+d+'" class="btn btn-indigo url_add">' +
' ADD URL' +
' ' +
' </button>' +
' </div>' +
'' +
' <div class="form-group ">' +
' <button type="button" data-id="'+d+'" class="btn btn-indigo url_refresh">' +
' REFRESH' +
' ' +
' </button>' +
' </div>' +
'' +
' </form>' +
' ' +
' </div>' +
'</div>' +
'' +
' <table class="table table-hover" id="url_table_'+d+'">' +
' <thead>' +
' <tr>' +
'<th data-orderable="false"><div class="form-check"><input type="checkbox" class="form-check-input position-static" id="selectAll"></div></th>'+
' <th>URL Name</th>' +
' <th>TC</th>' +
' <th>UC</th>' +
' <th>DC</th>' +
' <th>FC</th>' +
' <th>Status</th>' +
' </tr>' +
' </thead>' +
' </table>' +
'</div>' +
'';
return table;
}
});
Its all working fine but Now I am looking for refresh table data on click button, I am trying to refresh table like below on button click but its giving me error called
Uncaught TypeError: oInnerTable.draw is not a function
My button click code for refresh table is like this
$(document).on('click','.url_refresh',function(){
oInnerTable.draw();
});
I think its variable related issue but I am not understanding or getting idea how to use it properly so I can achieve my goal.
Thanks!
how to sum total in individual column searchable data table and how to add date range
please give me some suggestion.
how to add auto subtotal calculation of filtered data and add a date range in an individual column searchable data table.
this is the html
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
</tr>
<tr>
<td>Bruno Nash</td>
<td>Software Engineer</td>
<td>London</td>
<td>38</td>
<td>2011/05/03</td>
<td>$163,500</td>
</tr>
<tr>
<td>Sakura Yamamoto</td>
<td>Support Engineer</td>
<td>Tokyo</td>
<td>37</td>
<td>2009/08/19</td>
<td>$139,575</td>
</tr>
<tr>
<td>Thor Walton</td>
<td>Developer</td>
<td>New York</td>
<td>61</td>
<td>2013/08/11</td>
<td>$98,540</td>
</tr>
<tr>
<td>Finn Camacho</td>
<td>Support Engineer</td>
<td>San Francisco</td>
<td>47</td>
<td>2009/07/07</td>
<td>$87,500</td>
</tr>
<tr>
<td>Serge Baldwin</td>
<td>Data Coordinator</td>
<td>Singapore</td>
<td>64</td>
<td>2012/04/09</td>
<td>$138,575</td>
</tr>
<tr>
<td>Zenaida Frank</td>
<td>Software Engineer</td>
<td>New York</td>
<td>63</td>
<td>2010/01/04</td>
<td>$125,250</td>
</tr>
<tr>
<td>Zorita Serrano</td>
<td>Software Engineer</td>
<td>San Francisco</td>
<td>56</td>
<td>2012/06/01</td>
<td>$115,000</td>
</tr>
<tr>
<td>Jonas Alexander</td>
<td>Developer</td>
<td>San Francisco</td>
<td>30</td>
<td>2010/07/14</td>
<td>$86,500</td>
</tr>
<tr>
<td>Shad Decker</td>
<td>Regional Director</td>
<td>Edinburgh</td>
<td>51</td>
<td>2008/11/13</td>
<td>$183,000</td>
</tr>
<tr>
<td>Michael Bruce</td>
<td>Javascript Developer</td>
<td>Singapore</td>
<td>29</td>
<td>2011/06/27</td>
<td>$183,000</td>
</tr>
<tr>
<td>Donna Snider</td>
<td>Customer Support</td>
<td>New York</td>
<td>27</td>
<td>2011/01/25</td>
<td>$112,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
and this is the javascript
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable({
initComplete: function () {
// Apply the search
this.api().columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
}
});
} );
please give me some suggestion
count item filtered and show in the page
Hi all,
I'm searching a way to count items filtered and show the result in the html page, on the bottom or on the top.
For example if you see this demo:
http://live.datatables.net/geconesi/1/
what I need is a box or something else, on the bottom/top area of the page, that catch dynamically the total number of each single column of the table... do you think can be possible?
Sort Issue with Special Character in Multiple column
Link to test case:
https://jsfiddle.net/Uzair92/g7shyw2f/1/
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Above is the URL of my Actual Grid.
In the grid, there are strings and special characters.
I am unable to sort 2, 3 (Net Worth, Cash) Column in the grid, there are some negative values as well in the grid,
so Kindly fix the issue in the JSfiddle.
Display name with corresponding id on table
Hi all,
I would like to display the name of someone on table2. The data is organized as below:
table1: person
id
firstName
lastName
...
table2: bookings
booking_id
person_id <-- same as person.id, same person_id can present multiple times in table2
...
I would like to display the firstName and lastName on the datatable when viewing table2.