Cannot get Buttons csv working in DataTables 1.10.11 - datatables

I am upgrading an existing site that was using DataTables 1.9.4 and TableTools 2.0.3 to use DataTables 1.10.11. I cannot get the csv button to show up on my page.
I replaced
"oTableTools": {
"sSwfPath": "scripts/jquery/TableTools-2.0.3/media/swf/copy_csv_xls.swf",
"sRowSelect": "multi",
"aButtons": [
{
"sExtends": "text",
"sButtonText": t.cmdMarkSelectedInvoiced,
"fnClick": function (nButton, oConfig, oFlash) {
vr.markSelectedInvoiced();
}
},
{
"sExtends": "csv",
"sButtonText": t.cmdExportSelectedToCSV,
"bSelectedOnly": true
},
{
"sExtends": "csv",
"sButtonText": t.cmdExportAllToCSV
},
{
"sExtends": "select_none",
"sButtonText": t.cmdDeselectAll
}
]
},
with
"buttons": ['csv'],
the new initialization for the datatable is:
var bla = $('#someelement').DataTable({
"buttons": [
'csv'
],
"pagingType": "simple",
"destroy": true,
"stateSave": true,
"stateSaveCallback": function (settings, data) {
vr.saveDtState(data);
},
"stateLoadCallback": function (settings) {
return vr.dtSavedState(settings);
},
"pageLength": 10,
"language": {
"emptyTable": t.tblInfoNoDesignRequestFound,
"infoEmpty": t.tblInfoNoDesignRequestFound,
"zeroRecords": t.tblInfoNoDesignRequestFound,
"info": ct.tblInfoTxtDisplayingXtoYofTotal,
"infoFiltered": ct.tblInfoTxtFilteredFromMax,
"lengthMenu": ct.tblInfoTxtShow + ' <select>' + '<option selected value=10>10</option>' + '<option value=15>15</option>' + '<option value=20>20</option>' + '<option value=25>25</option>' + '<option value=-1>' + ct.txtAll + '</option>' + '</select> ' + ct.tblInfoTxtRows,
"search": ct.tblInfoTxtFilter,
"paginate": {
"next": ct.tblInfoTxtNextPage,
"previous": ct.tblInfoTxtPreviousPage
}
},
"ordering": true,
"order": [],
"stripeClasses": [
'myodd',
'myeven'
],
"data": vr.dataObj.data,
"columns": [
{
"data": "companyLocation",
"title": ct.chCompanyLocation
},
{
"data": function (source, type, val) {
if (type === 'display' || type === 'filter') {
return u.jsonToLocalDate(source.requestStatusDateUtc, false);
}
return source.requestStatusDateUtc;
},
"title": ct.chDate
},
{
"data": function (source, type, val) {
return vr.formattedNameSizeAndOrient(source, type)
},
"title": ct.chLogoName
},
{
"data": function (source, type, val) {
return vr.formattedDrInfo(source, type)
},
"title": ct.chDRNumber
},
{
"data": "requestStatusDescription",
"title": ct.chStatus
},
{
"data": "invoiceAmount",
"title": ct.chInvoiceAmount,
"orderable": false,
"className": "rightJustify"
},
{
"data": "invoiceCurrency",
"bSortable": false
},
{
"data": "requestedBy",
"title": ct.chCreatedByName,
"orderable": false
}
],
"initComplete": function () {
vr.loadColumnSelects('viewRequestsDataTable', this, columnSelects);
}
});

You need to specify the dom: parameter.

Related

Vue3 Chart not updating after sending data into Data series in Apex Chart

When I send data into the apex chart array that I took from my json file with axios, the chart does not automatically renew itself in Vue3
With Axios, I fetch all the apexcharts in the json file and add them to the elementCustomize array. Then I push the data in the elementDataseries array into elementCustomize[i].options.series one by one, the data goes into the series of the related apexchart successfully, but I can't see the change in the chart in the page. I can see the data whenever I write a text in the page and save it.
Can you help me?
That is my json file
"elementCustomize": [
{
"id": "2023024145531",
"customizeId": 0,
"elementId": 2023024145531,
"pageId": 1,
"zone": "zone1",
"options": {
"series": [ {
"elementId" : 2023024145531,
"dataId" : 123453576978982,
"name" : "Data 1",
"data" : [-44,55,187,11,61,22,63,45,3]
}],
"chart": {
"type": "bar",
"height": 280,
"toolbar": {
"show": true,
"tools": {
"download": true,
"selection": true,
"zoom": true,
"zoomin": true,
"zoomout": true,
"pan": true,
"reset": true
}
}
},
"plotOptions": {
"bar": {
"horizontal": false,
"columnWidth": "55%",
"endingShape": "rounded"
}
},
"colors": [
"#0150581244",
"#2196F3",
"#4CAF50",
"#9C27B0"
],
"dataLabels": {
"enabled": false
},
"stroke": {
"show": true,
"width": 2,
"colors": [
"transparent"
]
},
"xaxis": {
"categories": [
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct"
]
},
"yaxis": {
"title": {
"text": "$ (thousands)"
}
},
"fill": {
"opacity": 1
},
"legend": {
"position": "top",
"horizontalAlign": "center"
},
"title": {
"text": "Multiple Bars",
"align": "left"
},
"tooltip": {
"y": {}
}
}
},
{
"id": "2023025111221",
"customizeId": 0,
"elementId": "2023025111221",
"pageId": 1,
"zone": "zone3",
"options": {
"series": [],
"chart": {
"type": "bar",
"height": 280,
"toolbar": {
"show": true,
"tools": {
"download": true,
"selection": true,
"zoom": true,
"zoomin": true,
"zoomout": true,
"pan": true,
"reset": true
}
}
},
"plotOptions": {
"bar": {
"horizontal": false,
"columnWidth": "55%",
"endingShape": "rounded"
}
},
"colors": [
"#0150581244",
"#2196F3",
"#4CAF50",
"#9C27B0"
],
"dataLabels": {
"enabled": false
},
"stroke": {
"show": true,
"width": 2,
"colors": [
"transparent"
]
},
"xaxis": {
"categories": [
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct"
]
},
"yaxis": {
"title": {
"text": "$ (thousands)"
}
},
"fill": {
"opacity": 1
},
"legend": {
"position": "top",
"horizontalAlign": "center"
},
"title": {
"text": "Multiple Bars",
"align": "left"
},
"tooltip": {
"y": {}
}
}
}
]
The process where I pull this data from the json and sync it into the array
onBeforeMount(async () => {
await api.get(jsonServerUrl+"elementCustomize?pageId="+pageID).then(response=>{
elementCustomize = response.data
})
}
That is my apex chart code
<div v-for="item in filteredCustomize('zone1')" :key="item.id" class="drag-item s-card">
<ApexChart
id="apex-chart-1 chart"
:height="item.options.chart.height"
:type="item.options.chart.type"
:series="item.options.series"
:options="item.options"
>
</ApexChart>
{{item.options.series}}
<div class="elementHeadBar hover" align="start">
<VButton icon="feather:edit-2" color="info" :loading="loading" raised #click="updateSeries(item)"> test push series </VButton>
</div>
</div>
filteredCustomize for filtering areas, because i have 3 column in page. zone1, zone2, zone3 etc.
const filteredCustomize=(e)=>{
return elementCustomize.filter(item => item.zone === e)
}
I am posting fake datas with updateseries function.
const updateSeries = (item)=> {
let matchingData = elementDataSeries.filter(e => e.elementId == item.id)
if (matchingData){
for(let i = 0; i < elementCustomize.length; i++) {
for(let j = 0; j < elementDataSeries.length; j++) {
if(elementCustomize[i].elementId === elementDataSeries[j].elementId) {
elementCustomize[i].options.series.push(elementDataSeries[j]);
}
}
}
}else{
console.log("no")
}
console.log(elementCustomize)
}
i tried watch but it doesn't work. i read something in forums. when post data into apexchart series, it have to re render automatically.

Transform json data for DataTables

I have data which looks like this.
{
"data": [
{
"c1": "datapt00",
"size": 40
},
{
"c1": "datapt001",
"size": 80
}
]
}
In HTML I am doing,
$(document).ready(function) {
$('#example').DataTAble ( {
"ajax": {
"url": "/data",
}} ); });
Is ther ean easy way to manipulate my data so its Datatable compliant?
This should do it:
var jsonData = {
"data": [
{
"c1": "datapt00",
"size": 40
},
{
"c1": "datapt001",
"size": 80
}
]
};
$('#example').DataTable({
"ajax": {
"type": 'POST',
"dataType": 'json',
"url": '/echo/json/',
"data": {
"json": JSON.stringify(jsonData)
},
"dataSrc": "data"
},
"columns": [{
"data": "c1"
}, {
"data": "size"
}]
});
Working JSFiddle here: https://jsfiddle.net/annoyingmouse/70d01vo0/

Add link in datatable cell

How can I add html tags inside a column of the datatable?
$('#example').DataTable( {
"ajax": {
"url": "ajax/lista_bozze.php",
"dataSrc": ""
},
"columns": [
{ "data": "num_ticket" },
{ "data": "cod_pro" },
{ "data": "name" },
{ "data": "rag_soc" },
{ "data": "date_ticket" },
{ "data": "cod_pro" }
]
} );
You can use render option to process the data inside a datatable column,
this is example of converting one column into a link:
$('#example').DataTable( {
"columnDefs": [ {
"targets": 0,
"data": "download_link",
"render": function ( data, type, row, meta ) {
return 'Download';
}
} ]
} );

How to use a nested json-based formation value in the jQuery.dataTables?

Now suppose I have a json data formation like this following:
{
"ServiceName": "cacheWebApi",
"Description": "This is a CacheWebApiService",
"IsActive": true,
"Urls": [{ "ServiceAddress": "http://192.168.111.210:8200", "Weight": 5, "IsAvailable": true },
{ "ServiceAddress": ",http://192.168.111.210:8200", "Weight": 3, "IsAvailable": true }]
}
Now what worries me is that the "Urls" is another nested json formation. So how to bind this value to the datatables? And have you got any good ideas (e.g:something like I only wanna show all the ServiceAddress)...
This should do what you need:
var data = [{
"ServiceName": "cacheWebApi",
"Description": "This is a CacheWebApiService",
"IsActive": true,
"Urls": [
{
"ServiceAddress": "http://192.168.111.210:8200",
"Weight": 5,
"IsAvailable": true
},
{
"ServiceAddress": ",http://192.168.111.210:8200",
"Weight": 3,
"IsAvailable": true
}
]
}];
$(function() {
var table = $('#example').dataTable({
"data": data,
"columns": [
{
"data": "ServiceName"
}, {
"data": "Description"
}, {
"data": "IsActive"
}, {
"data": "Urls[0].ServiceAddress"
}, {
"data": "Urls[0].Weight"
}, {
"data": "Urls[0].IsAvailable"
}, {
"data": "Urls[1].ServiceAddress"
}, {
"data": "Urls[1].Weight"
}, {
"data": "Urls[1].IsAvailable"
}
],
});
});
You should put your data in an array though. Working JSFiddle
EDIT
IF the number of Urls isn't defined then you could do something like this:
var table = $('#example').dataTable({
"data": data,
"columns": [
{
"data": "ServiceName"
}, {
"data": "Description"
}, {
"data": "IsActive"
}, {
"data": "Urls",
"render": function(d){
return JSON.stringify(d);
}
}
],
});
I guess that that isn't brilliant but you could do almost anything to that function, for instance:
var table = $('#example').dataTable({
"data": data,
"columns": [
{
"data": "ServiceName"
}, {
"data": "Description"
}, {
"data": "IsActive"
}, {
"data": "Urls",
"render": function(d){
return d.map(function(c){
return c.ServiceAddress
}).join(", ");
}
}
],
});

How can use sPageNextDisabled in Jquery datatable 1.9?

I have a datatable having 12 columns.
oTable = $('#NotificationsTable').dataTable({
"bDestroy": true,
"bFilter": true,
"bJQueryUI": true,
"bPaginate": true,
"bsorting": true,
"iDisplayStart": 0,
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"iDisplayLength": 25,
"bLengthChange": true,
"bServerSide": true,
"sAjaxSource": "URL",
"fnServerParams": function (aoData) {
aoData.push({ "name": "param", "value": "page" }
);
},
"aoColumns": [
{ "mData": "Col0", "sClass": "center" },
{ "mData": "Col1", "sClass": "center" },
{ "mData": "Col2", "sClass": "center" },
{ "mData": "Col3", "sClass": "center wrapword" },
{ "mData": "Col4", "sClass": "center" },
{ "mData": "Col5", "sClass": "center" },
{ "mData": "Col6", "sClass": "center" },
{ "mData": "Col7", "sClass": "center" },
{ "mData": "Col8", "sClass": "center" },
{ "mData": "Col9", "sClass": "center" },
{ "mData": "Col10", "sClass": "center" },
{ "mData": "Col11", "bSortable": true }
],
"fnInitComplete": function (oSettings, json) {
//Some function
},
}
});
oTable .columnFilter({
sPlaceHolder: "head:after", aoColumns: [
{ type: "text" }, { type: "text" }, { type: "text" }, { type: "text" },
{ type: "text" }, null, { type: "text" }, { type: "text" },
{ type: "text" }, { type: "text" }, { type: "text" }, { type: "text" }
]
});
Here I want to disable the NEXT button of the datatable when "ALL" entries are shown.
FYI: I am having one row already in the datatable but I never wanted to show that to the user.
The Next button always have the id <table_id>_next, the length menu <table_id>_length. in dataTables 1.9.x there is individual CSS classes for each button's enabled or disabled mode. Toggle those classes when length value is -1, the value of All. Finally unbind the Next page event from the button.
$('select[name="NotificationsTable_length"]').on('change', function() {
var $nextButton = $("#NotificationsTable_next");
if ($(this).val() == -1) {
$nextButton.toggleClass('paginate_disabled_next');
$nextButton.unbind('click');
} else {
$nextButton.toggleClass('paginate_enabled_next');
}
}).trigger('change');
1.9.4 demo -> http://jsfiddle.net/stgLt59d/
In dataTables 1.10.x there is just a single .disabled class targeting all the pagination buttons.
$('select[name="NotificationsTable_length"]').on('change', function() {
var $nextButton = $("#NotificationsTable_next");
if ($(this).val() == -1) {
$nextButton.addClass('disabled');
$nextButton.unbind('click');
} else {
$nextButton.removeClass('disabled');
}
}).trigger('change');
demo -> http://jsfiddle.net/20q6adng/