Apply CSS for Column Value using REST

Apply CSS for Column Value using REST

beginner_2018beginner_2018 Posts: 46Questions: 19Answers: 0
edited May 2018 in Free community support

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;
                }
             }

},

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • beginner_2018beginner_2018 Posts: 46Questions: 19Answers: 0

    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;
    }
    }
    }

  • beginner_2018beginner_2018 Posts: 46Questions: 19Answers: 0

    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 );
    }
    }
    }
    ],

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • beginner_2018beginner_2018 Posts: 46Questions: 19Answers: 0

    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 ] }
    ]

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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.

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    edited May 2018

    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

This discussion has been closed.