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

Time:05-03

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

CodePudding user response:

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;" >'; 
}                            
  • Related