0

I'm using DataTable jquery plugin to show some data in my app...

I have this column definition:

 columns: [
  { "data" : "appName" },
  { "data" : "uuid" },
  { 
   "data" : "Enabled",
   'render': function(data, type, row)
   {
   console.log(data)
  return '<input type="checkbox" checked = "' + data + '" >';
   }
   }

and coresponding fields in array of objects passed from jquery. console.log(data) returns proper value, true of false for every record in table, but checkbox is always checked.

What i'm doing wrong here?

0

1 Answer 1

3

return '<input type="checkbox" checked = "' + data + '" >';

On this line you're adding the attribute checked hence it is always checked:

return '<input type="checkbox"' + (data ? ' checked="checked"' : '') + '>';

(Note that the value of checked does not need to be "checked" or even present, the attribute is the only thing that needs to be present, but it's generally preferred to use some meaningful value.)

Edit:

As your data appears to be a string rather than a boolean you'll need to compare data to "true":

return '<input type="checkbox"' + (data == "true" ? ' checked="checked"' : '') + '>';

Sign up to request clarification or add additional context in comments.

2 Comments

Not working. i always have either true or false in "data"... so it's always return checked...
do you have true or false or do you have a string representing them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.