我在一个模态窗体中有一个数据表,我需要在服务器端动态加载它,我有一个输入,我捕获值,需要通过javascript(或其他方法不同于从modelAttribute对象获取它)来加载它表
这是数据表,我需要存储在#idCProp
输入
<table th:if="${entity.formulario == 'formPerson'}" class="table dataTable" dt:deferLoading="10" id="propDT" dt:reloadSelector="#reloadProponent" dt:table="true" dt:sortable="true" dt:displaylength="10" dt:dom='ftip' dt:url="@{/person/loadProponents/__${entity.id}__/ **VALUE FROM INPUT**}" dt:serverside="true">
<thead>
<tr>
<th dt:property="entity.id" dt:renderFunction="nameAndLastName">Persona</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalPost">Cargo</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalInstitution">Institución</th>
<th dt:property="sendMethod.name" dt:sortable="false">Método de envío</th>
<th class="operations" dt:sortable="false" dt:property="id" dt:renderFunction="idToUrlProp"></th>
</tr>
</thead>
</table>
<input type="hidden" id="idCProp"/>
这是控制器方法
@RequestMapping(value = "/person/loadProponents/{idPerson}/{idCandidature}", method = RequestMethod.GET)
public @ResponseBody DatatablesResponse<Proposal> loadProponents(@PathVariable("idPerson") Long idPerson,@PathVariable("idCandidature") String idCandidature,
@DatatablesParams DatatablesCriterias criterias, HttpServletRequest request) {
//Do some stuff...
}
如何发送idCandidature
变量?
答案 0 :(得分:2)
我认为更好的方法是使用dataTables API和docker-compose up
变量来执行此操作。
您的观看代码为:
request
在您的控制器中,您已经拥有了所需的一切:
<form id="searchForm">
<input type="hidden" id="idCProp"/>
<button class="btn btn-primary" type="button"
th:text="#{proposals.find}"
onclick="findProposals();"></button>
</form>
<table th:if="${entity.formulario == 'formPerson'}" class="table dataTable" dt:deferLoading="10" id="propDT" dt:reloadSelector="#reloadProponent" dt:table="true" dt:sortable="true" dt:displaylength="10" dt:dom='ftip' dt:url="@{/person/loadProponents/__${entity.id}__}" dt:serverside="true">
<thead>
<tr>
<th dt:property="entity.id" dt:renderFunction="nameAndLastName">Persona</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalPost">Cargo</th>
<th dt:property="entity.id" dt:sortable="false" dt:renderFunction="getProposalInstitution">Institución</th>
<th dt:property="sendMethod.name" dt:sortable="false">Método de envío</th>
<th class="operations" dt:sortable="false" dt:property="id" dt:renderFunction="idToUrlProp"></th>
</tr>
</thead>
</table>
<script th:inline="javascript">
function findProposals() {
oTable_propDT.columns(2).search($("#idCProp").val());
... // more parameters if you need
oTable_propDT.columns(n).search($("#yoursearchparameterfrominput").val());
oTable_propDT.draw();
}
</script>
最后你只需要编写构建@RequestMapping(value = "/person/loadProponents/{idPerson}", method = RequestMethod.GET)
public @ResponseBody DatatablesResponse<Proposal> loadProponents(@PathVariable("idPerson") Long idPerson, HttpServletRequest request) {
DatatablesCriterias criterias = DatatablesCriterias.getFromRequest(request);
DataSet<Proposal> dataset = proposalService.getProposalsDataset(criterias);
return DatatablesResponse.build(dataset, criterias);
}
的{{1}}方法,我认为这没什么特别的。