Laravel Route in JavaScript Function - javascript

I have the below section of my js file but instead of hard code http://127.0.0.1:8000/Edit/Fee/Category/1. I need to Pass laravel route like this
{{route('Edit.Fee.Category',$Category->id)}}
var initTable5 = function() {
var table = $('#kt_datatable5');
// begin first table
table.DataTable({
scrollY: '450vh',
scrollX: true,
scrollCollapse: true,
columnDefs: [{
targets: -1,
title: 'Actions',
orderable: false,
width: '125px',
render: function(data, type, full, meta) {
return '\
\
Click To Pay\
\
';
},
},
],
});
};

Related

How to get edited data from data table using jquery or javascript

I have a data table and I have one editable column int it. When I edit that column (make some value change), on click of a button outside the table I would like to collect the edited rows with newly entered data.
Can anyone pls help.
I have tried this
$('#dataTableId tbody').on( 'change', 'tr', function () {
alert( table.row( this ).data() );
} );
But the above is not showing the edited data
Here is my data table:
function createDataTable(tableData){
var table = $('#dataTableId').DataTable({
responsive: true,
searching: false,
select: true,
"stripeClasses": [ 'odd', 'even'],
paging: false,
info: false,
data: tableData,
'columnDefs': [{
/* width: '20%', targets: 0, */
'targets': 0,
'searchable': false,
'orderable': false,
'checkboxes': {
'selectRow': true
},
'className': 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
}
},
{
"targets": 3 ,
'className': 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="text" name="id[]">';
}
}
],
dom: '1Bfrtip',
select: {
style: 'multi'//,//os
//selector: 'td:first-child'
},
destroy: true,
'order': [[1, 'asc']],
"columns": [
{"title":"",
targets: 0,
data: null,
defaultContent: '',
"className": "dt-center1 dt-center2 dt-ownershipColor dt-checkboxes-cell",
orderable: false
},
{ "title":"BusinessName",
"className": "dt-center1 dt-center3 dt-ownershipColor hidden-xs",
},
{ "title":"Alternate1 ",
"className": "dt-center1 dt-center2 dt-ownershipColor hidden-xs",
},
{ "title":"Alternate2",
"className": "dt-center1 dt-center2 dt-ownershipColor hidden-xs",
}
],
} );
$('#dataTableId tbody').on('change', 'input[type="checkbox"]', function() {
$(this).parent().parent().toggleClass('selected');
$(this).parent().parent().edit();
} );
$("#Deletebtn").click(function(){
var table = $('#dataTableId').DataTable();
var rowData = table.rows('.selected').data().toArray();
alert(rowData);
});
$("#Updatebtn").click(function(){
var table = $('#dataTableId').DataTable();
var rowData = table.rows('.selected').data().toArray();
alert(rowData);
});
$('#dataTableId tbody').on( 'change', 'tr', function () {
alert( table.row( this ).data() );
} );
}

Datatables problem's on render data into input

I am currently maintenance on some project using Datatables:
I found a problem when export the column that is successfully displayed on page failed to display after use render as below :
this._dataTable = this.$mainTable.DataTable({
ajax: {
url: this.url,
dataSrc: ''
},
dom: 'Bfrtip',
fixedColumns: {
leftColumns: 3,
rightColumns: 1
},
orderable: false,
rowId: 'fsId',
scrollX: true,
scrollCollapse: true,
columns: [{
className: 'input-cell',
data: 'stadate',
render(data) {
const time = data ? moment(data).format('HH:mm DD-MM-YYYY') : '';
return time;
},
width: '100px'
},
{
className: 'input-cell',
data: 'slotTime',
render(data) {
const time = data ? moment(data).format('HH:mm') : '';
return `<input name="slotTime" class="form-control" data-time value="${time}" size="5" readonly>`;
},
width: '72px'
},
],
buttons: [{
extend: 'print',
customize: function(win) {
$(win.document.body).find('table')
.addClass('compact')
.css('font-size', 'inherit');
}
}]
});
Data in column stadate can be displayed successfully, both on webpage and export page, but data slotTime successfully displays on webpage only.
Appreciate for any solution to fix it.. regards
finally, I can found sollution from here Datatables - Export values inside and outside the field input and value of the select field and here my final code :
this._dataTable = this.$mainTable.DataTable({
ajax: {
url: this.url,
dataSrc: ''
},
dom: 'Bfrtip',
fixedColumns: {
leftColumns: 3,
rightColumns: 1
},
orderable: false,
rowId: 'fsId',
scrollX: true,
scrollCollapse: true,
columns: [{
className: 'input-cell',
data: 'stadate',
render(data) {
const time = data ? moment(data).format('HH:mm DD-MM-YYYY') : '';
return time;
},
width: '100px'
},
{
className: 'input-cell',
data: 'slotTime',
render: function (data, type, row) {
const time = data ? moment(data).format('HH:mm') : '';
return type === 'export' ? time : `<input name="slotTime" class="form-control" data-time value="${time}" size="5" readonly>`;
},
width: '72px'
},
],
buttons: [{
extend: 'print',
exportOptions : {
orthogonal: 'export',
},
}]
});
thx all

How do I call a Vue.js method from a link inside data table?

I am building a Vue.js application using the Vue Webpack template. Within a component, I am initializing a Datatable like this:
<script>
export default {
name: 'DataTable',
mounted() {
$('#datatable').dataTable({
serverSide: true,
ajax: {
url: '/tableData',
},
processing: true,
searching: false,
pageLength: 25,
order: [[0, 'desc']],
columns: [
{
searchable: false,
data: 'updatedAt',
render: data => format(new Date(data), 'MMM Do, YYYY - h:mm:ss a'),
},
{
orderable: false,
data: 'user',
render: (data) => {
return `${data.firstName} ${data.lastName}`;
},
},
{
searchable: false,
orderable: false,
render() {
return 'View Details';
},
},
],
});
},
methods: {
openModal() {
console.log('Open modal code goes here');
}
}
}
</script>
This works fine and the table is rendered in the browser. My question - how do I call the openModal() method from inside the data table? As you can see, I am trying to call the method in columns[2].render but that doesn't work (likely because Vue does not compile the return string. How can I make this work?
you can add a click event on datatable callback.
Hope this helps
mounted() {
var self = this;
$('#datatable').dataTable({
serverSide: true,
ajax: {
url: '/tableData',
},
processing: true,
searching: false,
pageLength: 25,
order: [[0, 'desc']],
columns: [
{
.........
},
{ title: 'Action', targets:7, data: 'id',
"render":function(data, type, row, meta){
//data item in case you want to send any data
return 'Open Modal';
}
}
],
"drawCallback": function( settings ) {
$(".open-item").on( 'click', function (e) {
self.OpenModal(e.target.dataset.itemId);
});
}
});
},
methods: {
openModal:function() {
console.log('Open modal code goes here');
}
}

Problems displaying array data for datatables

I'm having problems display data in datatables, if I put the array straight in like this it works
$.parseJSON("[[\"1\",\"New Zealand\",\"20\"],[\"2\",\"Australia\",\"30\"]]");
but when I do it using a variable it doesn't it says read the error docs https://datatables.net/manual/tech-notes/4
I don't understand what's going on here
var self = this;
var data = $.parseJSON(self.model.get('shipping'));
// data is in this format [["1","New Zealand","20"],["2","Australia","30"]]
var intfreight = $('#edit-int-freight').DataTable(
{
//"aoColumnDefs": [{ "aTargets": [ 2 ] }] ,
'columnDefs': [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
],
data: data,
columns: [
{ title: 'id' },
{ title: 'country', searchable: true},
{ title: 'shipping_rate',
render: function (data, type, row) {
return '$' + data;
}},
{ title: 'action', orderable: false, searchable: false, render: function() {
return '<a class="delete" href="#edit/delete-freight">Delete</a>';
}}
]
});

Datatable does not print all my rows on scrolling

I am trying to get rows from back-end response on each scroll. I get
an AJAX response, but I can't get full row, it eats up the data
most probably the last one.
I tried with so other alternative, but it's not working at all, I tried redraw and reload in AJAX.
Here goes my js code:
var table= $('#subscriber_list').DataTable({
responsive: true,
"processing":true,
serverSide: true,
"scrollCollapse":true,
"sDom":"BifrtS",
scrollY:'35vh',
scrollCollapse: true,
paging:false,
"oScroller": {
"displayBuffer": 2,"loadingIndicator": true
},
"ajax": {"url": $('#data_table_column_list').attr("url"),"type": 'POST',"data":{'type':subscriber_type,'end_date_from':end_date_from,'end_date_to':end_date_to}},
"columns": JSON.parse($('#data_table_column_list').val().replace(/\'/g, '"')),
"columnDefs": [
{ "orderable": false, "targets": 2 }
],
buttons: [
{
extend: 'excelHtml5',
text: 'Export selected',
exportOptions: {
columns: ':visible:not(.not-exported)',
modifier: {
selected: true
}
},
title: 'Data export'
},
{
extend: 'excelHtml5',
text: 'Export All',
exportOptions: {
columns: ':visible:not(.not-exported)'
},
title: 'Data export'
}
]
});
You need one or both of the following depending on how you want the table to work.
Right now, it's getting cut off because the default in Datatables is 10 rows. You have paging set to false, so any results after the 10th are now shown.
Either switch this: paging:false,
to: paging:true,
That'll give you multiple pages of results with 10 on each page.
You can also add "pageLength": 50 or some other value if you want more than 10 rows per page.
here i am using same data table from multiple radio button switch, on switching i get warning from data table can't be re-initialised , since i know when i use table.destroy(); it destroy's all the object's created at while i switch the options, but have alternate to use it , what to do now ???? , running out of idea
i was referring this actually
https://datatables.net/manual/tech-notes/3
$('.subscriber_type').on('change',function (e){
var table = $('#subscriber_list').DataTable();
subscriber_data_table($(this).val(),$('#datepicker_from').val(),$('#datepicker_to').val());
});
subscriber_data_table("all",null,null);
function subscriber_data_table(subscriber_type,end_date_from,end_date_to) {
$('#subscriber_list').DataTable({
responsive: true,
"processing": true,
serverSide: true,
paging:true,
"pageLength":50,
"drawCallback": function( settings ) {
console.log( 'hit began' );
},
"sScrollY": "379",
"sDom":"BifrtS",
"oScroller": {
"displayBuffer": 2,"loadingIndicator": true
},
"ajax": {"url": $('#data_table_column_list').attr("url"),"type": 'POST',"data":{'type':subscriber_type,'end_date_from':end_date_from,'end_date_to':end_date_to}},
"columns": JSON.parse($('#data_table_column_list').val().replace(/\'/g, '"')),
"columnDefs": [
{ "orderable": false, "targets": 2 }
],
buttons: [
{
extend: 'excelHtml5',
text: 'Export selected',
exportOptions: {
columns: ':visible:not(.not-exported)',
modifier: {
selected: true
}
},
title: 'Data export'
},
{
extend: 'excelHtml5',
text: 'Export All',
exportOptions: {
columns: ':visible:not(.not-exported)'
},
title: 'Data export'
}
]
});
}

Categories