Add action buttons in vue.js frontend when using server side dataTables - laravel

How to add action buttons in frontend vue.js when using server side dataTables?
here is what i have so far, this code is working, but action buttons not give the request when clicking. (the alert is not also firing). the action buttons are showing and calling to editTaxGroup()
$(document).ready(function() {
let tax = 1;
self.dataTable = $("#tax_groups2").DataTable({
serverSide: true,
ajax: {
"columns": [
{ "data": "tax_group_name" },
{ "data": "country.country_name" },
{ "data": "tax_rate_percentage" },
{ "data": "Edit" },
{ "data": "Delete" }
],
data: {
"token": localStorage.getItem("token"),
},
url: 'api/v1/get-tax-groups',
dataFilter: function(data){
var json = jQuery.parseJSON( data );
json.recordsTotal = 100;
json.recordsFiltered = 100;
self.tax_groups = data.data;
return JSON.stringify( json ); // return JSON string
}
},
columns: [
{data: "tax_group_name"},
{data: "country.country_name",},
{data: "tax_rate_percentage"},
{data: "Edit"},
{data: "Delete"},
],
"columnDefs": [
{
"targets": [ -2 ],
"data":"id",
"defaultContent" : '<i class="fas fa-pen"></i>'
},
{
"targets": [ -1 ],
"data":"id",
"defaultContent" : '</i>'
}
],
});
})
$('#tax_groups2 tbody ').on('click', '#edit', function () {
for (let key in self.tax_groups){
alert(1)
console.log(key);
if(self.tax_groups.hasOwnProperty(key)){
console.log(`${self.tax_groups[key]}`)
}
}
} );
});
},

This isn't using Vue at all. You could actually more efficiently use Vue to generate these tables dynamically and set buttons as well. You may want to remove the Vue tag or re-ask the question.

Related

dataTable ajax URL not working in laravel 5.0

In my application using dataTable. In that ajax URL we are using. But while running, error message showing url not found kind. But it is there in route file. Why it showing like that?
My dataTable code is,
var oTable = $('.table').DataTable({
"oLanguage": {
"sSearch": "Search all columns:"
},
searching: false,
"processing": true,
"serverSide": true,
"ajax": {
"url": "{{ URL::to('loadfeedback') }}",
"data": function (d) {
d.from_date = $('#from_date').val();
}
},
"columns": [
{"data": null},
{"data": "name"},
],
'columnDefs': [
{
"searchable": false,
"orderable": false,
"targets": 0
},
],
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
var index = iDisplayIndex + 1;
$('td:eq(0)', nRow).html(index);
return nRow;
},
'iDisplayLength': 25,
"sPaginationType": "full_numbers",
"dom": 'T<"clear">lfrtip',
"order": [[0, 'desc']]
});
In routes.php
Route::get('loadfeedback', 'HomeController#loadfeedback');
In Controller.php
public function loadfeedback() {
$input = Input::all();
return Admin::loadfeedback($input);
}
What's wrong on this? And also it's working fine in my local system. After hosting only this issue found. But only this url, others are working fine.
Please help me.

Datatables: Button for Showing Photo for Each Filename

I am very new to Datatables and this might be simple, but surely I am missing something. I am trying to create a button column that uses the filename of each row and uses it to make an ajax call to display a picture on click. What I get wrong is that, every button of the column displays the same image, and not the image of the filename for each row. Here is the code:
$.ajax ({
url: "http:// ...... /Services/DBPrintDatatable?customer_id=" + projectid,
type: "GET",
dataType: 'json',
async: false,
success: function(data) {
$('#projectsdt').show();
projectsTable = $('#projectsdt').DataTable({
"pageLength": 10,
"data": data,
"scrollX": true,
"aaSorting": [],
"columns": [
{ "data": "upload_date" },
{ "data": "filename" },
{ "data": "uploader" },
{ "data": "upload_place" },
{ "data": "is_ok" },
{ "data": "custom_verdict" },
{
data: { "data": "filename" },
render: function ( data, type, row ) {
return "<a data-fancybox='gallery' class='btn btn-success' href='http://......./Services/DBShowImage?filename='+ { 'data': 'filename' }>Show</a>";
}
},
] ,
});
Thank you in advance!
If the image url required is like
http://......./Services/DBShowImage?filename=filenameFromData
Then you should generate it first inside the render like below code
href='http://......./Services/DBShowImage?filename="+ row.filename+"';
render: function ( data, type, row ) {
return "<a data-fancybox='gallery' class='btn btn-success' href='http://......./Services/DBShowImage?filename="+ row.filename+"'>Show</a>";
}

ExtJS: How to hide specific data on store with filtering?

I want to hide a record on Grid that returns from server.
I've setted a filter on store and can reach that specific data but how I'll handle to hide/ignore this record?
fooStore: {
....
filters: [
function(item) {
let me = this;
let theRecord = item.data.status === MyApp.STATUS; //true
if (theRecord) {
console.log(theRecord); //True
console.log("So filter is here!!")
//How to hide/ignore/avoid to load this specific data record to load Grid??
}
}
]
},
Returned JSON;
{
"success": true,
"msg": "OK",
"count": 3,
"data": [
{
//Filter achives to this record and aim to hide this one; avoid to load this record.
"id": 102913410,
"status": "P"
},
{
"id": 98713410,
"status": "I"
},
{
"id": 563423410,
"status": "A"
}
]
}
I can't save my fiddle cause i don't have sencha forum's account so i give you my code :
Ext.application({
name : 'Fiddle',
launch : function() {
var model = Ext.create('Ext.data.Model', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'status', type: 'string'},
]
});
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
model: model,
proxy: {
type: 'ajax',
url: 'data.json',
reader: {
type: 'json',
rootProperty: 'data'
}
},
filters: [function(item) {
if (item.data.status === "P") {
return true;
}
else {
return false;
}
}],
listeners: {
load: {
fn: function() {
console.log(this.getRange());
}
}
}
});
}
});
Also i create data.json like this :
{
"success": true,
"msg": "OK",
"count": 3,
"data": [{
"id": 102913410,
"status": "P"
}, {
"id": 98713410,
"status": "I"
}, {
"id": 563423410,
"status": "A"
}]
}
I thinks it's near to you'r code and after the loading of the store the filter work as you can this :
Here is sencha fiddle link : https://fiddle.sencha.com/#view/editor
If this can't work, i don't understand what the fuck doing...

How to modify Datables data while binding to the view in Laravel?

Here is my existing JS code:
var CategoriesTablewithFilter = function(){
var table = $('#catDatatable');
var url = $('#url').val();
var tableObj = table.DataTable( {
"serverSide": true,
"responsive": true,
"aoColumnDefs": [
{ "bSearchable": true, "aTargets": [ 1 ] },
],
ajax:
{
url: url,
dataSrc: 'data',
},
columns: [
{ data: 'id'},
{ data: 'name'},
{ data: 'status'},
],
} );
}
Status is a Boolean field which returns 1 or 0.
Is there anyway I can change 1, 0 to Strings - Active/InActive
You should use render function for column:
var CategoriesTablewithFilter = function () {
var table = $('#catDatatable');
var url = $('#url').val();
var tableObj = table.DataTable({
"serverSide": true,
"responsive": true,
"aoColumnDefs": [
{"bSearchable": true, "aTargets": [1]},
],
ajax:
{
url: url,
dataSrc: 'data',
},
columns: [
{data: 'id'},
{data: 'name'},
{data: 'status', render: function (data, type, row, meta) {
return data == 1 ? 'Active' : 'InActive';
}}
],
});
}
Try debugging you ajax response using console.log(data) output to fetch status's value and use render function to display render the final output.
columns: [
{ data: 'id'},
{ data: 'name'},
{
data: 'status',
render: function (data, type, full, meta) {
return full.status == true ? 'Active' : 'Inactive';
}
}
]
Or you could use
columns: [
{ data: 'id'},
{ data: 'name'},
{
data: 'status',
render: function (data, type, full, meta) {
return data === '1' ? 'Active' : 'Inactive';
}
}
]

Datatable Editor's "new" form posts empty values

after one week of search/tests/debugging and headaches... I'm kindly seeking your help on the following problem: Consider the following simple piece of code (I'm focusing on the POST only):
var editor = new $.fn.dataTable.Editor( {
ajax: {
create: {
type: 'POST',
url: '/employees'
},
edit: {
type: 'PUT',
url: 'XXXXXXXX'
},
remove: {
type: 'DELETE',
url: 'XXXXXXXX'
}
},
table: "#example",
fields: [ {
label: "First name:",
name: "first_name"
}, {
label: "Last name:",
name: "last_name"
}, {
label: "Position:"
name: "position"
}
]
} );
$('#example').DataTable( {
dom: "Bfrtip",
ajax: "/employees",
columns: [
{ data: "first_name" },
{ data: "last_name" },
{ data: "position" },
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
} );
When I submit the form, it posts empty values for the 3 fields! Do I need to serialize Editor's form fields?
I'm using Laravel as PHP MVC The related "#example" datatables displays data correctly, no problem on that.
I just want to use the client side Datatable...
Thanks a lot for your help!
Actually the form is posting values... However I get them as "urlencode" and can't use them in my controller... Will post another question...

Resources