Reputation: 21236
I'm using Materialize and I'm trying to make a table that contains checkboxes. However, there seems to be a problem. A checkbox contained within a table doesn't seem to work. I'm not sure if this a bug or if I'm not doing something correct:
<form action="#">
<table>
<thead>
<tr>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>My Label</td>
<td><input type="checkbox" class="filled-in" /><label></label></td>
</tr>
</tbody>
</table>
</form>
How do I make a checkbox contained within a table using Materialize?
Upvotes: 7
Views: 20533
Reputation: 211
Try this:
<label>
<input type="checkbox" />
<span>*** Need text here ***</span>
</label>
Wrapping everything in a label
element with a span
right under it was the only way I was able to get my checkboxes to display.
Upvotes: 2
Reputation: 553
I have written a small piece of code which will transform the data of nested array of objects into materialize table with check box , so if you dont want to view either of the column just select or deselect it .
// Using the Materilize css Check boxes change the functionality of the check bocx accordingly
var tab= document.getElementById("TransformTable");
//Get The No of Cols from the JSON data
var NoOfCols=Object.getOwnPropertyNames(data[0]); //Insert the row for the table headings var row = tab.insertRow(0); //set the attribute row.setAttribute("id",0+"_row"); /** * Loop for No of Cols and set the heading and append the CheckBox */ for(var i=0;i<NoOfCols.length;i++){ var cell1 =row.insertCell(i); cell1.setAttribute("id","0_row"+i+"_cell"); cell1.innerHTML="<b>"+NoOfCols[i]+"</b>";
$("#checkBoxDiv").append("<input type='checkbox' id="+i+" checked='checked' style='margin:10px;'/><label for="+i+" style='margin-right:10px;'>"+NoOfCols[i]+"</label>"); } /** *Loop for the Table data */ // Loop for the no Of rows for(var j=0;j<data.length;j++){ var row2=tab.insertRow(j+1); row.setAttribute("id",(j+1)+"_row"); // Lopp for the No of Cols in a row for(var k=0;k<NoOfCols.length;k++){ var cell2=row2.insertCell(k); cell2.setAttribute("id",(j+1)+"_row"+k+"_cell"); cell2.innerHTML=data[j][NoOfCols[k]]; } } /** event Listener for the check Boxes */ $("input").click(function(event){ var id = event.target.id; if($("#"+id).prop("checked")){ DisplayTable(id); }else{ HideTable(id); } }); /** * [HideTable Hide the col of a table]
*/ function HideTable(id){ var ColId =id; for(var t=0;t<=data.length;t++){ $("#"+t+"_row"+ColId+"_cell").css("display","none"); } } /** * [DisplayTable Display the col of a table]
*/ function DisplayTable(id){ var ColId =id; for(var t=0;t<=data.length;t++){ $("#"+t+"_row"+ColId+"_cell").css("display","table-cell"); } }
Upvotes: 0
Reputation: 79022
You did not have an id
for the checkbox and matching for
attribute for the label:
<input type="checkbox" id="myCheckbox" class="filled-in" />
<label for="myCheckbox"></label>
http://jsfiddle.net/xcmsLee9/1/
Upvotes: 18