user18243370
user18243370

Reputation: 51

How to apply conditional checking on input columns in a JavaScript Datatable

Below shows one of a column in my javaScript Datatable:

       {
            "className": 'child_grid',
            "data": function (data) {
                return '<input disabled id="comment" data - val="true" type = "text" value = "' + data.LookupComment + ' != null ? ' + data.LookupComment + ' : """ style = "height: 2rem !important;" >';
            }                    
        },

Here I have check for null value in the input field. If it is null, want to show blank. For that I have applied condition in the value="" property. But instead of checking condition, it is printing whole conditions in the UI.

If I directly use the value variable in the input value property, it displays null in case of null value as given below.

enter image description here

Upvotes: 0

Views: 90

Answers (1)

jna
jna

Reputation: 996

What about creating the value prior to the return?
Something like this..

"data": function(data) {
  const value = data.LookupComment !== null ? data.LookupComment : '';
  return '<input disabled id="comment" data-val="true" type="text" value="value" style = "height: 2rem !important;" >'; 
}                            

Upvotes: 1

Related Questions