Datatables responsive, set specific options - datatables

I am using DataTables with the responsive extension on our web application, but I have a question.
When the table is made responsive, it should hide the pagination option.
I tried this with "bLengthChange": false:
$(function () {
$("#table1").DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Dutch.json"
},
"order": [[1, "asc"]],
"bAutoWidth": false,
responsive: {
details: {
type: 'column'
},
"bLengthChange": false
},
columnDefs: [ {
className: 'control',
orderable: false,
targets: 0
} ],
});
});
However, this does not work. My target is that I can see the pagination amount dropdown menu on fullscreen, but that option should be hidden if responsive.
Can I add options like bLengthChange specific to the "responsive" state?

Can I add options like bLengthChange specific to the "responsive"
state?
No, you cannot. Try inspect $.fn.dataTable.Responsive.defaults again, as I believe you already have done. It does not give so much sense either, the responsive extension is an extension while lengthMenu is a core feature. If you want to hide the lengthMenu you would need to reinitialise the table or do something hackish that may or may not conflict with other features or other extensions. But you can do the hack yourself. Hook into the responsive-resize event and hide or show the lengthMenu according to the responsive status :
table.on( 'responsive-resize', function ( e, datatable, columns ) {
var $lengthMenu = $('.dataTables_length')
var count = columns.reduce( function (a,b) {
return b === false ? a+1 : a;
}, 0 );
if (count>0 && $lengthMenu.is(':visible')) $lengthMenu.hide()
if (count<= 0 && !$lengthMenu.is(':visible')) $lengthMenu.show()
} );
demo -> http://jsfiddle.net/v1dnxLkg/

Thank you.
Fixed it with this CSS:
#media screen and (max-width: 767px){
div.dataTables_wrapper > div.row > div > div.dataTables_length{
display: none;
}
}

Related

vue-chartjs remove top rectangle (datasets label)

render chart view
how the chart looks
So I feel like I've tried everything under the sun to remove that red rectangle above the chart. Anyone know how to remove it? Most of the examples with setting up options and legend like below might work with chartjs but not vue-chartjs if I'm not mistaken.
options: {
legend: {
display: false,
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
You litterly posted the answer yourself, the second object in the renderChart function is the options object so if you put it like this it will work:
{ responsive: true, maintainAspectRatio: true, legend: { display: false } }
Next time please dont post a screenshot of your code but include it as text in your post since it is a lot easyer to read and use for people

canvasOverlay show in jqplot

How do I trigger on the overlays in jqplot only after I click a checkbox (not when the html loads). When I first set overlay option show to false the overlays are not displayed on plot at 1st and when I used my trigger function the overlays do not appear.
Here is the code I use for the plot :
<div id="fastest" style="margin-top:20px; margin-left:20px; margin-right:200px; width:800px; height:400px;">
<script class="code" type="text/javascript">
$(document).ready(function(){
var dataset="too long to be displayed here"
plot1 = $.jqplot('fastest', dataset, {
title: 'Test_figs',
legend: {show:false},
series: [{
showMarker: false,
color: '#ED0E0E',
label: 'R spectrum',
neighborThreshold: -1
}],
axes:{
xaxis:{
label:'Restframe Wavelength'
},
yaxis:{
label:'Flux',
tickOptions:{formatString:'%.3e'}
}
},
cursor:{
show:true,
zoom:true,
tooltipLocation:'sw'
},
Canvasoverlay: {
show: false,
objects: [
{verticalLine: {
name: 'Na-ID',
x: 5893.000000,
lineWidth: 2,
color: '#F0630C',
lineCap:'butt',
yOffset:0,
shadow: true
}}
]
}
});
});
function NaID_trigger() {
var co = plot1.plugins.canvasOverlay;
var line = co.get('Na-ID');
if (line.options.show==false) line.options.show = true;
else line.options.show = false;
co.draw(plot1);
}
</script>
I then use :
<button onclick="NaID_trigger()">Na-ID</button>
to trigger the overlay on or off for instance.
PS: I tried replacing draw by replot as advised didn't work when show=false in overlays options.
I finally found the solution myself :
to not display the overlays when the jqplot loads I set the overall overlays "show" option to true.
Then within each object I set show to false.
Instead of the external to the plot function I used before I switched to an even handler of the form:
$("input[type=checkbox][name=Na-ID]").change(function(){
plot1.plugins.canvasOverlay.get('Na-ID').options.show = this.checked;
plot1.replot();
});
Now the plot display the selected overlay when checkbox is ticked and not at the beginning.
Hope this will help someone who has the same issues.

Datatables table header & column data misaligned when using "sScrollY"

Having problems with my table header becoming misaligned when I use "sScrollY". The header realigns itself only after I sort a certain column by clicking on one of the headers.
Misaligned.
Corrected only After I click on a sort header.
My Setting:
oTable = $('#userslist').dataTable({
"bJQueryUI": true,
"bRetrieve": true,
"sScrollY": "150px",
"bAutoWidth" : true,
"bPaginate": false,
"sScrollX": "100%",
"sScrollXInner": "100%",
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"sDom": '<"H"lfr>t<"F"<"useraccountbtn">>',
"aaData": datan,
"aoColumns": [
{ "mDataProp": "uid"},
{ "mDataProp": "fn" },
{ "mDataProp": "un" },
{ "mDataProp": "pw" },
{ "mDataProp": "em" },
{ "mDataProp": "ac" }
]
});
I've also tried fnAdjustColumnSizing() which every Google Search seems to be suggesting but it doesn't do anything for me.
I have fix this way;
wrap the table with div and
CSS
overflow:auto;
height: 400px;
position:relative;
Remove
“sScrollY”
"sScrollX"
I've had to delay when data is loaded because when page loads it does not see the scroll bar and table headers get misaligned. But if I delay it, it sees the scroll bar and the table header matches up perfect.
<button onclick="delayload('loadusers()')">Load Table</button>
function delayload(f){
setTimeout(f,50)
}
function loadusers() {
oTable = $('#userslist').dataTable({
"bJQueryUI": true,
"bRetrieve": true,
"sScrollY": "150px",
"bAutoWidth" : true,
"bPaginate": false,
"sScrollX": "100%",
"sScrollXInner": "100%",
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"sDom": '<"H"lfr>t<"F"<"useraccountbtn">>',
"aaData": datan,
"aoColumns": [
{ "mDataProp": "uid"},
{ "mDataProp": "fn" },
{ "mDataProp": "un" },
{ "mDataProp": "pw" },
{ "mDataProp": "em" },
{ "mDataProp": "ac" }
]
});
}
I had to remove the scrolling manually, because nothing else worked. Then I used #Suresh Kamrushi 's answer to make an external scrolling div
Here's the code if anyone needs it :)
//replace all scroll-related divs with their content (aka unwrap the content)
$('.table-responsive').replaceWith($('.table-responsive').html());
$('.dataTables_scroll').replaceWith($('.dataTables_scroll').html());
$('.dataTables_scrollHead').replaceWith($('.dataTables_scrollHead').html());
$('.dataTables_scrollBody').replaceWith($('.dataTables_scrollBody').html());
$('.dataTables_scrollHeadInner').replaceWith($('.dataTables_scrollBody').html());
$('.dataTables_sizing').each(function (index, value) {
$(this).replaceWith($(this).html());
});
//Re-size the header
$('#table_view_subs thead tr').attr("style","height:37.6px");
//add external scroll div
$("#table_view_subs").wrap("<div style='overflow:auto; width:100%;position:relative;'></div>");
It's very hacky, but if you've lost a week and your patience trying to get the DataTable to behave, you're not gonna care
Well, whenever you sort or filter and the contents of the table change in some way, fnDraw gets called. If an extra fnDraw is working (via clicking your sorting header after the table has loaded), and it isn't tied to bServerSide then trying an extra call to oTable.fnDraw() couldn't hurt.
Using ScrollX or scrollY create such problems. there is a work around for it:
$('#userslist').DataTable({
"initComplete": function (settings, json) {
$("#reportDetails").wrap("<div style='overflow:auto; width:100%;position:relative;'></div>");
},
});
First remove ScrollX or scrollY if you have in your page and add above code to fix it.
Try this:
$($.fn.dataTable.tables(true)).DataTable().columns.adjust();
I also had problems with ScrollX.
With wide tables it is a very big help. With narrow tables, as in the problem case above, I also had the same problem.
The problem arises because 3 tables are also made in one table. One for the header, one for the data and one for the footer.
The data part has the correct width. The header and footer are too short, so I enlarged them using CSS:
// Scroll-X
DIV.dataTables_scrollHeadInner,
DIV.dataTables_scrollFootInner{
min-width: 100%;
}
DIV.dataTables_scrollHeadInner > TABLE,
DIV.dataTables_scrollFootInner > TABLE{
min-width: 100%;
}

Rails + Multiple DataTables + UI nested accordion

I'm using multiple similar dataTables within a nested UI accordion. While I've had no problem initializing multiple dataTables using the class-level selector, I'm having a problem getting the header and footer of any given table to align correctly.
I assume this is the same problem as a dataTable in a tab: the table (or header) needs to be redrawn once the accordion pane is displayed.
With initialization of a single table, or id-based initialization, I've had no problem using fnDraw or fnAdjustColumnSizing in a function to redraw a table on display. However, using mass-initialization, this approach doesn't work, because the specific displayed table can't be easily targeted.
I've tried to find a way of targeting only the currently displayed table for redraw, but haven't been successful.
Has anyone else dealt with this issue successfully? Thanks for any ideas....
I'm sure this is super-hacky, but the only way I could set it up so I could create a dynamic, multi-level accordion with a dataTable nested within each, was to actually nest the dataTable initialization within the accordion activation (at the level of the table), then mark the table div as initialized so it could be re-opened. Here's my js code:
$(document).ready(function(){
$(function() {
$('.accordion.second-level').bind('accordionactivate', function (event, ui) {
if (ui.newPanel.length) {
thisPanel = ('#'+ ui.newPanel.attr('id'));
if ($(thisPanel).hasClass('not_activated')) {
$(thisPanel + ' .dataTables_types').dataTable({
"bAutoWidth": false,
"bPaginate": false,
"bScrollCollapse": true,
"sScrollY": "295px",
"aaSorting": [[ 1, "desc" ]],
"sDom": "<'row'<'span10'f>>t<'row'<'span10'i>>",
"aoColumns": [
{ "bSortable": false },
null,
null,
{ "iDataSort": 4 },
{'bVisible': false},
{'bVisible': false},
null
],
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
/* Calculate the total transactions on this page */
var total = 0;
for ( var i=iStart ; i<iEnd ; i++ )
{
total += aaData[ aiDisplay[i] ][5]* 1;
}
var nCells = nRow.getElementsByTagName('th');
nCells[1].innerHTML = total;
$(nCells[1]).formatCurrency({negativeFormat:'%s-%n'});
}
});
$(thisPanel).removeClass('not_activated');
}
}
});
});
});
I'd still love to know if there's a better/more efficient way to do this, but this does work.

Grid Panel Scrollbars in Extjs 4 not working

var gusersPanel = Ext.create('Ext.grid.Panel', {
flex:1,
columns: [{
header: 'User Login',
dataIndex: 'user_login',
width:150
},{
header: 'User Name',
dataIndex: 'user_nicename',
width:150
},{
header:'Privledge',
dataIndex:'admin',
width:150
}],
autoScroll: true,
layout:'fit',
selModel: gusersSel,
store: gusersStore
})
Hi I am using above code for the grid Panel in Extjs4.0.2a When I populate data dynamically in the store the scrollbars are not working .
I have also tried using doLayout() for grid Panel but dosent work too .
The grid Panel is in a Window .
Anything that can solve this problem ?
Actually it works for some time but dosen't work all the time .
I've had the same problem. They use custom scrollbar and it's pretty buggy (especialy in chrome). If you are not going to use infinite scroll the possible solution could be to remove custom scrollbar and use native one. To do that just add the following to the grid's config:
var gusersPanel = Ext.create('Ext.grid.Panel', {
scroll : false,
viewConfig : {
style : { overflow: 'auto', overflowX: 'hidden' }
},
// ...
});
I did gusersPanel.determineScrollbars() when i am adding and removing data from store and it is working fine .
The problem with this is the scroll listener is attached to the div element on the afterrender event, but then if the scrollbar is not needed after a layout operation the div element is removed from the dom. Then, when it's needed again it's added back, but only if enough time has passed the garbage collection makes extjs recreate the div node and this time it's added to the dom without attaching the scroll listener again. The following code solves the problem:
Ext.override(Ext.grid.Scroller, {
onAdded: function() {
this.callParent(arguments);
var me = this;
if (me.scrollEl) {
me.mun(me.scrollEl, 'scroll', me.onElScroll, me);
me.mon(me.scrollEl, 'scroll', me.onElScroll, me);
}
}
});
You written code to layout: 'fit'. It did not work autoScroll.
Change the code to some height and remove layout: 'fit' code.
Like this.
var gusersPanel = Ext.create('Ext.grid.Panel', {
flex:1,
columns: [{
...........
}],
autoScroll: true,
//layout:'fit',
height: 130,
selModel: gusersSel,
store: gusersStore
It is help you. Cheers.