I'm working with a Laravel Blade file. I want to export the table to PDF, and it seems to work correctly. However, there is a problem while displaying the image. It only shows the image path, not the image after exporting.
exportOptions: {
stripHtml: false,
Added but not working
$(document).ready(function() {
var buttonCommon = {
extend : 'pdfHtml5',
exportOptions: {
stripHtml: false,
columns: 'th:not(:last-child)',
exportOptions: {
stripHtml: false,
//columns: 'th:not(:nth-child(2))',
format: {
body: function ( data, row, column, node ) {
// Strip $ from salary column to make it numeric
return column === 4 ?
data.replace( /[$,]/g, '' ) :
data;
}
}
}
}
};
//$.noConflict();
$('.datatable').DataTable({
processing: true,
serverSide: true,
//"oSearch": { "bSmart": false, "bRegex": true },
ajax: '{{ route('customers.getdata') }}',
columns: [
{data: 'id', name: 'id'},
{data: 'profilepic', name: 'profilepic',render: function( data, type, full, meta ) {
if(data==0) { return "<img src=\"/customers/default.png" + "\" height=\"50\"/>"; } else { return "<img src=\"/customers/" + data + "\" height=\"50\"/>"; }
}},
{data: 'name', name: 'name'},
{data: 'email', name: 'email'},
{data: 'phone', name: 'phone'},
{data: 'address', name: 'address'},
{data: 'created_by', name: 'created_by'},
{data: 'status', name: 'status',render: function( data, type, full, meta ) {
if(data==1) { return "Active"; } else { return "Inactive"; }
}},
{data: 'action', name: 'action', orderable: false, searchable: false}
],
dom: 'Bfrtip',
buttons: [
$.extend( true, {}, buttonCommon, {
extend: 'copyHtml5',
} ),
$.extend( true, {}, buttonCommon, {
extend: 'excelHtml5',
} ),
$.extend( true, {}, buttonCommon, {
extend: 'pdfHtml5',
} )
]
});
});
I need an image view rather than an image path.
Related
Here's my ID column data structure
ID: [1,2,3,4,5,6,7,8]
Here is my controller's code.
$transaction = ExpenseEntry::with('transaction');
return DataTables::eloquent($transaction)
->editColumn('transaction', function (ExpenseEntry $expense) {
return $expense->transaction->map(function ($transaction) {
return $transaction->id;
});
})->make(true);
and Javascript Function
$(document).ready(function () {
$('#data-table').DataTable({
"ordering": false,
"processing": true,
"serverSide": true,
"ajax": '{!! route('
expense_dts ') !!}',
columns: [{
data: 'id',
name: 'id'
},
{
data: 'expense_type',
name: 'expense_type'
},
{
data: 'amount',
name: 'amount'
},
{
data: 'date',
name: 'date'
},
{
data: 'description',
name: 'description'
},
{
data: 'transaction',
name: 'transaction.id'
}
]
});
});
It is working but the problem is it is showing all the transacation.id in a table like this [1,2,3,4,5,6]
I want to get them like each id in each row with its column.
I use yajra-laravel-datatable (laravel 5.6).
I have put jquery-uniform radio button in datatable but that is not working.
I use $.uniform.update() but it is not working.
$(".styled_color_checkbox").uniform({
radioClass: 'choice',
wrapperClass: 'border-indigo-600 text-indigo-800'
});
Blade file code
var oTable = $('.finance_payment_datatable').DataTable({
processing: false,
serverSide: true,
ajax: {
url: '{!! route('admin.finance.invoice.datatable') !!}',
data: function (d) {
var customer_id = $(".customer_select option:selected").val();
if (typeof customer_id == 'undefined'){
customer_id = '0';
}
if (customer_id !== '0') {
d.customer_id = customer_id;
}
}
},
columns: [
{data: 'maincheck', sortable: false, orderable: false, searchable: false},
{data: 'invoice_number', name: 'invoice_number', sortable: true},
{data: 'created_at', name: 'created_at', sortable: true},
{data: 'outstanding_price', name: 'outstanding_price', sortable: true},
],
order: [[2, 'desc']],
"pagingType": "full_numbers",
"language": {
"emptyTable": "No invoice to display",
"search": '<span>Filter:</span> _INPUT_',
"lengthMenu": '<span>Show:</span> _MENU_',
},
autoWidth: false,
'fnDrawCallback': function( oSettings ) {
$.uniform.update();
}
});
Controller file code
public function invoiceDatatable(Request $request) {
$raw = Invoice::with('user')->select('invoices.*');
if ($request->has('customer_id')) {
$raw->where('invoices.user_id', $request->get('customer_id'));
}
$raw->where('invoices.outstanding_price', '>=', '1');
$datatable = app('datatables')->of($raw)
->addColumn('maincheck', function ($raw) {
return '<label><input type="radio" name="invoice" class="styled_color_checkbox outstanding_price" data-amount="'.$raw->outstanding_price.'" value="'.$raw->id.'"></label>';
})
->editColumn('created_at', function ($raw) {
return date('Y/m/d', strtotime($raw->created_at));
})
->editColumn('outstanding_price', function ($raw) {
return '$'.$raw->outstanding_price;
});
return $datatable->make(true);
}
I'm using Laravel 5.4 and Yajra datatable, below is my code working properly but in the 2nd action I've created, The button is not displaying but instead it display the text itself "Add Price" What am I missing ?
public function getProductDatatable()
{
$Product = Product::query();
return Datatables::eloquent($Product)
->addColumn('action', function($row) {
return 'Edit';
})
->addColumn('add_price', function($row) {
return 'Add Price';
})
->make(true);
}
Frontend Part
<script type="text/javascript">
$(function() {
$('#product-table').DataTable({
processing: true,
serverSide: true,
ajax: '{{ url('product/get_product_datatable') }}',
columns : [
{data: 'id', name: 'id'},
{data: 'product_code', name: 'product_code'},
{data: 'action', searchable: false, orderable: false},
{data: 'add_price', searchable: false, orderable: false},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'}
]
});
});
</script>
You need to define rawColumns :
public function getProductDatatable()
{
$Product = Product::query();
return Datatables::eloquent($Product)
->addColumn('action', function($row) {
return 'Edit';
})
->addColumn('add_price', function($row) {
return 'Add Price';
})
->rawColumns(['add_price', 'action'])
->make(true);
}
I found this issue on github, try adding rawColumns
Datatables::eloquent($Product)
->addColumn(..)
->rawColumns(['add_price']);
I'm using Laravel Datatables 7, but my table is not rendering HTML code. It was rendering HTML before, but when I updated to new Laravel DataTables to 7 from 6, it stopped rendering HTML in column.
http://prntscr.com/e11n84
This is with Laravel DataTables 6 - http://prntscr.com/e11ph0
$(function() {
$('#users-table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ route("admin.access.user.get") }}',
type: 'post',
data: {status: 1, trashed: false}
},
columns: [
{data: 'id', name: '{{config('access.users_table')}}.id'},
{data: 'name', name: '{{config('access.users_table')}}.name', render: $.fn.dataTable.render.text()},
{data: 'email', name: '{{config('access.users_table')}}.email', render: $.fn.dataTable.render.text()},
{data: 'confirmed', name: '{{config('access.users_table')}}.confirmed'},
{data: 'roles', name: '{{config('access.roles_table')}}.name', sortable: false},
{data: 'created_at', name: '{{config('access.users_table')}}.created_at'},
{data: 'updated_at', name: '{{config('access.users_table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[0, "asc"]],
searchDelay: 500
});
});
Add the column with html as shown on other answers and after all add this ->rawColumns(['html_column', 'another_html_column']) before ->toJson() to render all the html column as sent by the server
Try to feed data as JSON from the controller by using toJson() method.
$data= User::all();
return datatables()->of($data)
->addColumn('action', function ($row) {
$html = 'Edit ';
$html .= '<button data-rowid="'.$row->id.'">Del</button>';
return $html;
})->toJson();
Ref: https://laravelarticle.com/laravel-yajra-datatables
//im also using yajra data tables..
//it's easy to render html from controller...
example:
$query = Appointment::all();
$table = Datatables::of($query);
$table->editColumn('user_id', function ($row) {
return $row->user_id ? '<span style="color: green;">ACCEPTED</span>' :
'<span style="color: red;">PENDING</span>';
});
//then you need to add the column you want to render html
$table->rawColumns(['user_id']);
I have the following code:
The Store :
Ext.define('strClientesRECO', {
extend: 'Ext.data.Store',
model: 'mdlClientesRECO',
autoLoad: false,
proxy: {
type: 'ajax',
pageParam: undefined,
startParam: undefined,
limitParam: undefined,
api: {
read: 'some url',
create: 'some url',
update: 'some url',
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success',
messageProperty: 'message'
},
writer: {
root: 'records',
encode: true,
writeAllFields: false
}
}
});
The grid has the following properties:
selModel: Ext.create('Ext.selection.CheckboxModel'),
selType: 'cellmodel',
plugins: [{
ptype: 'cellediting',
clicksToEdit: 2
}],
In the controller I have a listener to sync the store every cell update
Ext.ComponentQuery.query('viewGridClientesRECO')[0].getStore().addListener('update', this.onUpdateRecords, this);
onUpdateRecords: function() {
var storeGridClientes = Ext.ComponentQuery.query('viewGridClientesRECO')[0].getStore();
storeGridClientes.sync();
},
But in the PHP file that is executed when I update, if I print $_POST the records sends are correct, but it never sends the id of the edited row.