dataTables add Font Awesome icon instead of column name - datatables

I'm new in DataTables and I have a simple datatable for which I'm trying to add a Font Awesome fa-info-circle image instead of one column header by using render like:
table = $("#datatable-buttons").DataTable({
data: document.pvm.tableContent(),
columns: [
{ data: "Info", render: function (data, type, full, meta) { if (type === 'display') return '<span style="font-size:75%" class="fa fa-info-circle"></span>' } },
{ data: "WiFi", title: "WiFi" },
{ data: "GPS", title: "GPS" },
],
fixedHeader: true,
dom: "lfBrtip",
buttons: [
{
extend: "copy",
className: "btn-sm"
},
{
extend: "csv",
className: "btn-sm",
filename: "DeviceMnag"
},
{
extend: "excel",
className: "btn-sm",
filename: "DeviceMnag"
},
{
extend: "pdfHtml5",
className: "btn-sm",
filename: "DeviceMnag"
},
{
extend: "print",
className: "btn-sm"
},
],
});
But it seems that my icon instead of being just in the header for Info column, there is no icon in the header but in the data columns instead of the correct data. Is is possible to add a icon just for one field in the header?

I believe when you are saying "column header" you mean the title? render() is for rendering column data, you set the column header through the title property :
var table = $('#example').DataTable({
columnDefs: [{
targets: 0,
data: '0', //just use DOM
title: '<i class="fa fa-info-circle fa-lg"></i>'
}]
})
demo -> http://jsfiddle.net/6kp3tvpb/
title can be a function as well :
title: function() {
return '<i class="fa fa-info-circle fa-lg"></i>'
}
But notice that this callback only is called once.

Related

How to adjust datatables DOM elements

I have 2 questions:
Anyone knows how to make the search bar and label in one line? (red circle) Currently its 2 lines.
Preferably using the dom attribute, if possible. Or any other simple and quick method.
How to remove the space between table header and body? (yellow space). css, js methods are welcomed!
Here's my datatables initialization:
table = $('#serviceItemList').DataTable({
processing: true,
serverSide: true,
scrollResize: false,
scrollY: 300,
scrollCollapse: true,
paging: false,
info: false,
createdRow: function (row, data, dataIndex) {
$(row).attr('data-id', data.id);
},
dom: 'Bfrtip',
ajax: {
'url': "/serviceitem/list",
'type': "POST",
'data': function (data) {
data.zone = zone;
}
},
columns: [
{ data: 'checkbox', name: 'items[]' },
{ data: 'DT_RowIndex', name: 'DT_RowIndex' },
{ data: 'zone', name: 'zone', orderable: true, },
{ data: 'code', name: 'code', orderable: true, },
{ data: 'description', name: 'description', searchable: true },
],
select: {
style: 'multi',
selector: 'td:first-child'
},
});
you can try it by inspecting the element and look for its class name and then you can set the display property to none
and for the search bar do the same and set the float property to left

Display Selected values in v-select multiple

I am new in vue js. Using vue2, I have a v-select implemented on my site now, I want to select multiple values and save and show them while editing. But I can't show multiple values properly using :reduce
Here is my code:
<v-select name="allowed_extensions"
:reduce="allowed_extensions => allowed_extensions.value"
multiple
:closeOnSelect="false"
v-model="form.allowed_extensions"
:options="file_options"
v-validate="'required'" > </v-select>
In js:
data () {
return {
isDisabled: false, //Submit Button
form: {
maximum_file_size: '',
allowed_extensions: ''
},
be_errors: {},
// Options
file_options: [
{ label: 'doc', value: 'doc' },
{ label: 'docx', value: 'docx' },
{ label: 'pdf', value: 'pdf' },
{ label: 'txt', value: 'txt' },
{ label: 'gif', value: 'gif' },
{ label: 'png', value: 'png' },
{ label: 'jpg', value: 'jpg' },
{ label: 'jpeg', value: 'jpeg' }
]
}
}
IN Mysql DB, sample data saved as : ["doc","txt"]
But when I want to display them in edit, it showing wrongly in a single tag.
How can I solve this

Data table footer is not included in DataTable print export option

I am using a Codeigniter and ajax request with DataTable to fetch data and trying to print the data using DataTable print export option. But footer is not appearing in the print.
How can i include the footer in printing with DataTable?
Here is my code:
function data_table_report(dateselected){
$("#dataTables-report").dataTable().fnDestroy();
table = $('#dataTables-report').DataTable({
"ajax": {
"url": "<?php echo site_url('patients_report/dataTable_report/')?>"+dateselected,
"type": "POST",
},
responsive: true,
bInfo: false,
dom: 'Bfrtip',
buttons: [{ extend: 'print',
exportOptions: {
columns: ':visible'
}
},
'colvis'],
columnDefs: [ {
targets: -1,
visible: false}
]
});
}
Add this:
buttons: [{ extend: 'print', footer: true }]
Add footer property as shown below
buttons: [{ extend: 'print',
footer: true,
exportOptions: {
columns: ':visible'
}
}]
Try this:
"fnInitComplete": function (oSettings, json) {
myfooter = this.find('tfoot')[0].innerHTML;
new $.fn.dataTable.Buttons( this, {
buttons: [
{
extend: 'print',
exportOptions : {
columns: ':not(.notForPrint)'
},
customize: function ( win ) {
$(win.document.body)
.css( 'font-size','10pt')
.css( 'font-family','arial');
$(win.document.body).find( 'table' )
.addClass( 'compact' )
.css( 'font-size', 'inherit' );
$(win.document.body).find('tfoot')[0].innerHTML = myfooter ;
win.print();
setTimeout(win.close(),500);
}
}
]
});
this.DataTable().buttons().container().insertBefore( '#example_filter');
},

Cannot read property 'oFeatures' of undefined datatables

I am getting this error Cannot read property 'oFeatures' of undefined datatables I am using bubble editing of datatable editor
<script type="text/javascript">
var editor;
$(document).ready(function(){
// use a global for the submit and return data rendering in the examples
editor = new $.fn.dataTable.Editor( {
ajax: 'http://52.77.155.163/web/index.php?r=ivision/productprices/datatable',
table: '#example',
fields: [ {
label: "Id:",
name: "id"
},
],
formOptions: {
inline: {
onBlur: 'submit'
}
}
} );
$('#example').on( 'click', 'tbody td', function (e) {
var index = $(this).index();
if ( index === 0 ) {
editor.bubble( this );
}
});
var table=$('#example').DataTable( {
ajax: 'http://52.77.155.163/web/index.php?r=ivision/productprices/datatable',
dom: "Bfrtip",
scrollY: 300,
paging: false,
bSort: false,
columns: [
{ data: "id" },
{ data: "getcat(cat_id)" },
{ data: "getproduct(p_id)" },
{ data: "m_price" },
{ data: "c_price" },
{ data: "e_price" },
{
data: null,
defaultContent: 'Delete',
orderable: false
}],
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
} );
});
</script>
I am getting this error in console, Cannot read property 'oFeatures' of undefined . I am using bubble editing for datatables.net editor.
I also get this error.
It was the issue, Editor's table property is different DataTable Id.
After use same Id, it's fixed.

Hide column in dgrid dynamically

How to hide complete column in dgrid (gridFromHtml) based on some run time parameter?
Lets say if the value of parameter is true I should be able to display some column and if the value is false then I should be able to hide that same column.
Use grid.styleColumn(columnId, css):
var grid = new Grid({
store: store,
columns: [
{ id: "artist", label: "Artist", field: "Artist"},
{ id: "name", label: "Song", field: "Name"},
{ id: "gerne", label: "Genre", field: "Genre"}
]
}, "grid-placeholder");
// to hide column with id="name"
grid.styleColumn("name", "display: none;");
// to show it
grid.styleColumn("name", "display: table-cell;");
There is a dgrid extension called ColumnHider which allows you to pass in a column with a "hidden" property.
require([
"dojo/_base/declare", "dgrid/OnDemandGrid", "dgrid/extensions/ColumnHider"
], function(declare, OnDemandGrid, ColumnHider) {
var grid = new(declare([OnDemandGrid, ColumnHider]))({
columns: {
col1: {
label: "Column 1",
hidden: true
},
col2: {
label: "Column 2",
unhidable: true
},
col3: "Column 3"
}
}, "grid");
// ...
});
This will also give the user the ability to hide their own columns. You can set some columns to be unhidable, like column 2 above
You need to use toggleColumnHiddenState:
require([
'dojo/_base/declare',
'dgrid/OnDemandGrid',
'dgrid/extensions/ColumnHider'
], function (declare, OnDemandGrid, ColumnHider) {
var grid = new (declare([ OnDemandGrid, ColumnHider ]))({
columns: {
'id': {label: '#'},
'name': {label: 'Название'}
}
}, 'grid');
grid.toggleColumnHiddenState('name', true); // hiding
grid.toggleColumnHiddenState('name', false); // showing
grid.toggleColumnHiddenState('name'); // toggling column
});
Should think this will work
var grid = new dojox.grid.DataGrid({
store: dataStore,
structure: [{
name: "ID",
field: "id",
width: "100px"
}, {
name: "Values",
field: "values",
width: "100px"
}]
}, "myGrid");
grid.startup();
function showOrHideColumn(show, widget, index) {
var d = show ? "" : "none"
dojo.query('td[idx="'+index+'"]', widget.viewsNode).style("display", d);
dojo.query('th[idx="'+index+'"]', widget.viewsHeaderNode).style("display", d);
}
showOrHideColumn(false,grid,0);