Have a table with some data loaded from server by provised ajax to DataTable, also have yadcf for filtering on server side. In one of columns i have select2 box, in what i want see only predefined (loaded from server) options (in example on jsfiddle it is opt variable), but options in select2 contains also data from column. How i can disable adding column data, and stay only loaded from server options?
https://jsfiddle.net/6ssh8mg4/
code:
var opts = [{id:0, text:"Some 1"},{id:1, text:"Some 2"}];
var table = $("#docTable").DataTable({
processing: true,
serverSide: false,
paging: true,
ordering: true,
deferRender: true,
pageLength: 10,
lengthMenu: [[10, 50, 100, -1], [10, 50, 100, "All"]],
columns: [
{ "data": "Identifier", className: "nowrap" },
{ "data": "Name" },
]
});
yadcf.init(table, [
{ column_number: 0, filter_type: "text", style_class: "form_control", filter_default_label: "" },
{
column_number: 1, filter_type: "select", select_type: "select2", filter_default_label: "",
select_type_options: {
data: opts,
width: '180px',
dropdownAutoWidth: true,
}
},
]);
You should use the data attribute (in your case with data/label properties), read the docs
Here is a working sample
var opts = [{value:0, label:"Some 1"},{value:1, label:"Some 2"}];
var table = $("#docTable").DataTable({
processing: true,
serverSide: false,
paging: true,
ordering: true,
deferRender: true,
pageLength: 10,
lengthMenu: [[10, 50, 100, -1], [10, 50, 100, "All"]],
columns: [
{ "data": "Identifier", className: "nowrap" },
{ "data": "Name" },
]
});
yadcf.init(table, [
{
column_number: 0, filter_type: "text", style_class: "form_control", filter_default_label: "" },
{
data: opts,
column_number: 1, filter_type: "select", select_type: "select2", filter_default_label: "",
select_type_options: {
width: '180px',
dropdownAutoWidth: true,
}
},
]);
jsfiddle
Related
Datatables allows you to use shift+select, while also allowing you to select single items without losing previously selected items by having the select style set to multi+shift.
'select': {style': 'multi+shift'}
However, for this datatable, that doesn't seem to work at all. What am I missing?
var $testTable = $("#test-list").DataTable({
"dom": '<"dataTables_top"i<"dataTables_custom_buttons">f>rt'+ '<"dataTables_bottom"ilp>',
"autoWidth": false,
"lengthChange": 100,
"lengthMenu": [[10, 25, 100, 200, 500, 1000], [10, 25, 100, 200, 500, 1000]],
"paging": true,
"pagingType": "full_numbers",
"stripeClasses": [ 'odd', 'even' ],
"order": [[1, 'asc']],
"language": {
"emptyTable": '<h3>Test...</h3>',
"search" : '',
"sLengthMenu" : "_MENU_ Per Page",
"info": "Showing _START_ to _END_ of _TOTAL_",
paginate: {
first: '<i class="fad fa-step-backward"></i>',
previous: '<i class="fad fa-backward"></i>',
next: '<i class="fad fa-forward"></i>',
last: '<i class="fad fa-step-forward"></i>'
}
},
'select': 'multi+shift',
"aoColumnDefs": [
{
"targets": [-1,-2,-3,-4,-5,-6,-7,-8,-9,-11],
'searchable': false
},
{
"targets": 'no-sort',
"orderable": false,
},
{
"targets": [8,11],
"visible": false
},
{
"iDataSort": 8,
"aTargets" : [7]
},
{
"iDataSort": 11,
"aTargets" : [10]
},
{
"targets": -1,
'searchable': false
}
],
"initComplete": function() {
......
},
"drawCallback": function(settings) {
......
}
});
I am trying to use "Fixed columns" feature in datatables with remote data pulled using ajax. Everything works perfectly without any errors. However, the "Fixed columns" feature doesn't work. Below is my code
$('#dataTable').DataTable({
"order": [[ groupColumn, "asc" ]],
"rowReorder": true,
"dom": 'l<"toolbar">frtip',
"scrollX": true,
"bscrollCollapse": true,
"displayLength": 25,
"fixedColumns": true,
"columnDefs": [
{ "visible": false, "targets": groupColumn },
{ "orderable": true, "targets": groupColumn },
{ "orderable": false, "targets": "_all" }
],
"processing": false,
"pageLength": 60,
"ajax": {
url: "http://example.com/output",
type: 'post',
data: {id:id}
},
"columns": {
//column definitions provided here
}
});
I've an issue with the option ScrollY in the two plugins YADCF 0.8.9 and DataTable 1.10.
I try to add some filters on my headers and to activate the option ScrollY but :
- With the option scrollY, I've no filter
- Without : works fine ! (obviously without "max height 400 px"
What can I do ?
JS :
var tableDataTbl = $("#MyDataTableTest").DataTable({
language: {
url: '/js/DataTables/fr_FR.json'
},
scrollY: 400,
paging : false,
scrollCollapse: true,
stateSave: true
});
yadcf.init(tableDataTbl,
[{
column_number: 0,
filter_type: "text"
}, {
column_number: 1,
filter_type: "range_number"
}, {
column_number: 2,
filter_type: "range_number"
}, {
column_number: 3,
filter_type: "range_number"
}, {
column_number: 4,
filter_type: "range_number"
}, {
column_number: 5,
filter_type: "range_number"
}, {
column_number: 6,
filter_type: "text"
}, {
column_number: 7,
filter_type: "text"
}]
);
This was fixed in 0.9.2.beta.2
see test page
It was an because of the language: {url: '...'}, and the scrollY: ..., were used together, anyway - it works now
I am using the latest version Jquery DataTables.net, and have a table that display a total of 10 records per page, with a max count of 1004.
However, in the info bar, this reads:
Showing 1 to 5 of 1.004
the default of my table is as follows:
var oMessageDate = $("#messageDateDT").DataTable({
dom: "<'row'<'col-sm-12'<'pull-right'T><'pull-left'l>r<'clearfix'>>>t<'row'<'col-sm-12'<'pull-left'i><'pull-right'p><'clearfix'>>>",
stateSave: true,
pageLength: 10,
lengthMenu: [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
columns: [
{ data: "MessageReference", sWidth: "15%" },
{ data: "Beneficiary" },
{ data: "Currency", sWidth: "5%" },
{ data: "Amount" },
{ data: "MessageDate", sWidth: "15%" },
{ data: "MessageType", sWidth: "5%" },
{ data: "Direction", sWidth: "5%"},
{ data: "Assigned", sWidth: "10%" },
{ data: "Status", sWidth: "17%" },
{ data: "Message" },
{ data: "MessageId", sWidth: "5%" },
{ data: "StatusCode" }
],
"autoWidth": false,
"pagingType" :"full_numbers",
language: {
"decimal": "-",
"thousands": ".",
"infoEmpty": "No entries to show",
"lengthMenu": "Display _MENU_ records",
"processing": "Loading data",
searchPlaceholder: "on everything",
"zeroRecords": "No records to display",
"aria": {
"sortAscending": ": activate to sort column ascending",
"sortDescending": ": activate to sort column descending"
}
},
"columnDefs": [
{ "visible": false, "targets": 9 },
{ "visible": false, "targets": 10 },
{ "visible": false, "targets": 11 }
]
});
Can you please advise, how I can correct this.
Your screenshot shows
Showing 1 to 10 of 1.004 entries
And your default pageLength option is 10 which would give you 101 pages.
This is just a section of my JSON Data string as it is quite extensive...
{
"total": 2,
"page": 1,
"records": 15,
"rows": [
{
"id": 2148,
"cell": {
"MRN": "840134833",
"Hospital_Fin": "987141516",
"First_Name": "YELLOW",
"Last_Name": "CRAYON",
"Date_of_birth": "/Date(1253160000000)/"}
}
]}
And this would be how I set up my jqGrid...
$(document).ready(function () {
jQuery("#frTable").jqGrid ({
cmTemplate: { sortable: false },
caption: '#TempData["POPNAME"]' + ' Population',
datatype: 'json',
mtype: 'GET',
url: '#Url.Action("GetAjaxPagedGridData", "Encounters", new { popId = TempData["POPULATIONID"] })',//'/Encounters/GetAjaxPagedGridData/'+ '',
pager: '#pager',
loadonce: true,
height: 450,
gridview: true,
viewrecords: true,
rowNum: 15,
shrinkToFit: false,
autowidth: true,
colNames: [
'MRN',
'Hospital Fin',
'First Name',
'Last Name',
'Date of birth'
colModel: [
{ name: 'MRN', width: 125, align: 'left' },
{ name: 'Hospital_Fin', width: 145, align: 'left' },
{ name: 'First_Name', width: 115, align: 'left' },
{ name: 'Last_Name', width: 115, align: 'left' },
{ name: 'Date_of_birth', width: 145, align: 'left', formatter:'date', formatoptions: {newformat: 'm/d/Y'}}]
Now...
I look through JSfiddle and I do get the Json string back in the right format. In fact, That is how I was able to copy and paste to this fine website. So what am I missing? It looks like everything should be about right?
UPDATE
Do my col models and the names of my columns in my cell have to match up 100 percent? Maybe that would be someplace to take a look?
You use wrong format of JSON data. Compare your data with the data expected by jqGrid described in the documentation. To fix JSON data you can change it to for example the following
{
"total": 2,
"page": 1,
"records": 15,
"rows": [
{
"id": 2148,
"MRN": "840134833",
"Hospital_Fin": "987141516",
"First_Name": "YELLOW",
"Last_Name": "CRAYON",
"Date_of_birth": "/Date(1253160000000)/"
}
]
}
You need include additionally jsonReader: {repeatitems: false} in the list of jqGrid options.