Apply CSS for Column Value using REST
Apply CSS for Column Value using REST
beginner_2018
Posts: 46Questions: 19Answers: 0
Dear All,
I have condition to apply the css and hide the column value if it is true for all the columns .
Can any one please do let me know how can I make it. I tried columnDefs , But it is hiding entire column .
.hide{
visibility: hidden;
}
{
"mData": "Plan",
render: function (data, type, row, meta ) {
if(data==null)
{
return "(Empty)";
}
else
{
return data;
}
}
},
{
"mData": "Score",
render: function (data, type, row, meta ) {
if(data==null)
{
return "(Empty)";
}
else
{
return data;
}
}
},
This discussion has been closed.
Answers
Hi @beginner_2018 ,
You want to hide the column if it contains all the same values? If so, I wouldn't use CSS for that, the best bet is to use the API's
column().visible()
method.Cheers,
Colin
Sir,
On retrieving the SharePoint list items I am trying to apply the column().visible() functionality ,On the condition if the value is "(Empty)" .
But I find no luck with below pieces of my code.
Can any one please do let me know what's wrong in it.Because I a trying to hide the column value if the condition is true
{
"mData": "Plan",
render: function (data, type, row, meta ) {
if(data==null)
{
return "(Empty)";
table.column .visible( false );
}
else
{
return data;
}
}
}
or is there any option to apply the condition for all the columns using columnDefs
columnDefs: [
{
targets: [ 0,1,2,3,8,9],
render: function ( data, type, row, meta ) {
if(data==null)
{
table.column .visible( false );
}
}
}
],
Hi @beginner_2018 ,
Take a look at this example here, it's hiding the first column if all the values are the same. You could expand that to cover the target array that you have in your example.
Cheers,
Colin
Sir,
I am not trying to hide the column , I am trying to display the value of the column.
Using columnDefs and with the help of Css I a able to hide the entire column.
But my requirement is to disable the value if the condition meets
"columnDefs": [
{ className: "hide", "targets": [ 11 ] }
]
You could trigger on a
draw
event, scan the data and change the class for that column if the data being displayed is all the same.Its a bit confusing to understand what you are trying to do. I put together an example that displays blank data if the value is "Software Engineer" in the Position column:
http://live.datatables.net/qikewodo/1/edit
Is this what you are looking for?
Kevin