I need to style the ds elements inside my table to have padding left and right equal to 0px and nothing I do affects them.
<table class="table table-borderless" style="overflow: scroll" width="100%" id="topAlarmsDeviceLine">
</table>
let tableModel = [
{
title: '',
type: 'html',
targets: 0,
data: function (source, type, val){
return source.Denumire;
}
},
{
title: '',
type: 'html',
targets: 1,
data: function(source, type, val) {
if (source.processor && source.processor > 59) {
return "<td style='padding: 0px !important;'>" + Math.round(source.processor / 60) + 'h' + "<span class='border border-dark-subtle border-2 border-start-0' style='background-color: #F0AD4E; width:10px; height:10px; display: inline-block; margin: 5px; vertical-align: middle;'></span></td>";
} else if(source.processor && 0 < source.processor && source.processor < 60) {
return "<td style='padding: 0px !important;'>" + source.processor + 'm' + "<span class='border border-dark-subtle border-2 border-start-0' style='background-color: #F0AD4E; width:10px; height:10px; display: inline-block; margin: 5px; vertical-align: middle;'></span></td>";
} else {
return "";
}
}
},
{
title: '',
type: 'html',
targets: 2,
data: function(source, type, val) {
if (source.ram && source.ram > 59) {
return "<td style='padding: 0px !important;'>" + Math.round(source.ram / 60) + 'h' + "<span class='border border-dark-subtle border-2 border-start-0' style='background-color: #5CB85C; width:10px; height:10px; display: inline-block; margin: 5px; vertical-align: middle;'></span></td>";
} else if(source.ram && 0 < source.ram && source.ram < 60) {
return "<td style='padding: 0px !important;'>" + source.ram + 'm' + "<span class='border border-dark-subtle border-2 border-start-0' style='background-color: #5CB85C; width:10px; height:10px; display: inline-block; margin: 5px; vertical-align: middle;'></span></td>";
} else {
return "";
}
}
},...
I have tried to add the td style in return, the way is is my example, but it doesn’t work.
I also tried to select the table td and use css jquery method, still nothing:
$(‘#topAlarmsDeviceLine td’).css(‘padding’, ‘0px’);
2
Answers
I can suppose you to set
!important
after because usingtable-borderless
may lead to some default style for the table and its child objects.Try
$('#topAlarmsDeviceLine td').css('padding', '0px !important');
You can check computed styles in the Developer’s pane and follow the rule that sets your current padding.
If you have a
data:
option which returns a<td style="...">foo</td>
string, that means you are trying to insert a<td>
element into the<td>
element which is automatically constructed by DataTables.In such cases, DataTables will remove your
<td>
and only show the inner text.So, this is what is happening in code such as:
You can try something like this:
In the above demo, the Position column attempts (and fails) to use styles in a
<td>
element; whereas the Office column uses a<span>
element. You can see the styles are successfully applied to the span.What you can do with this is limited – maybe too limited for your needs. You may need to experiment.
You can take a look at the DataTables default styling options. Those may also be too limited for your needs.
You can use another styling framework – one of those which is supported by DataTables. The DataTables download page has a list. See Step 1. Choose a styling framework.