我想要一个复选框列来选择多行。我设法在每一行上创建一个复选框,但我还希望在标签上有一个复选框,以便在我选中标题上的复选框时自动选择列上的所有复选框。我怎么能实现这个目标?
PS:我正在使用JSP
<form id="form">
<div style="text-align:right; padding-bottom:1em;">
<button type="submit">Submit form</button>
</div>
<datatables:table id="owners" data="${selections}" row="owner" theme="bootstrap2"
cssClass="table table-striped" pageable="false" info="false" export="pdf">
<datatables:column title="Name" cssStyle="width: 150px;" display="html">
<spring:url value="/owners/{ownerId}.html" var="ownerUrl">
<spring:param name="ownerId" value="${owner.id}"/>
</spring:url>
<a href="${fn:escapeXml(ownerUrl)}"><c:out value="${owner.firstName} ${owner.lastName}"/></a>
</datatables:column>
<datatables:column title="Name" display="pdf">
<c:out value="${owner.firstName} ${owner.lastName}"/>
</datatables:column>
<datatables:column title="Address" property="address" cssStyle="width: 200px;"/>
<datatables:column title="City" property="city"/>
<datatables:column title="Telephone" property="telephone"/>
<datatables:column title="Pets" cssStyle="width: 100px;">
<c:forEach var="pet" items="${owner.pets}">
<c:out value="${pet.name}"/>
</c:forEach>
</datatables:column>
<datatables:column sortable="false" filterable="false">
<input type="checkbox" name="check${owner.id}" value="${owner.id}">
</datatables:column>
<datatables:export type="pdf" cssClass="btn" cssStyle="height: 25px;" />
</datatables:table>
</form>
答案 0 :(得分:0)
您可以使用<datatables:columnHead>
标记自定义标题列。
<form id="form">
<div style="text-align:right; padding-bottom:1em;">
<button type="submit">Submit form</button>
</div>
<datatables:table id="owners" data="${selections}" row="owner" theme="bootstrap2"
cssClass="table table-striped" pageable="false" info="false" export="pdf">
...
<datatables:column sortable="false" filterable="false">
<datatables:columnHead>
<input type="checkbox" onclick="$('#owners').find(':checkbox').attr('checked', this.checked);" />
</datatables:columnHead>
<input type="checkbox" name="check${owner.id}" value="${owner.id}">
</datatables:column>
...
</datatables:table>
</form>
位于<datatables:columnHead>
标记内的所有内容都将放置在相应的列标题中。
参考:http://dandelion.github.io/datatables/docs/ref/jsp/columnhead.html