如何使用复选框过滤DataTable

时间:2015-07-28 14:47:17

标签: javascript java ajax playframework datatable

的JavaScript

这是我的dataTable选项和ajax调用:

<script type="text/javascript">
 $(document).ready(function() {
   var table = $('#datatable_fixed_column').dataTable( {
     "bProcessing": true,
     "aaSorting": [[ 0, "asc" ]],
     "bServerSide": true,
     "sPaginationType": "full_numbers",
     "sAjaxSource": "@controllers.routes.EntidadeController.listEntidades()"
            });
            $("div.toolbar").html('<div class="text-right"></div>');
        });
</script>

控制器

这是我的控制器,我的记录被过滤和排序:

public static Result listEntidades() {
        User user = Application.getLocalUser(session());
        Empresa empresa = Application.getEmpresaAtiva(user.id);
        Map<String, String[]> params = request().queryString();
        Integer iTotalRecords = Entidade.find.findRowCount();
        String filter = params.get("sSearch")[0];
        Integer pageSize = Integer.valueOf(params.get("iDisplayLength")[0]);
        Integer page = Integer.valueOf(params.get("iDisplayStart")[0]) / pageSize;
        String sortBy = "id";
        String order = params.get("sSortDir_0")[0];

        switch(Integer.valueOf(params.get("iSortCol_0")[0])) {
            case 0 : sortBy = "nome"; break;
            case 1 : sortBy = "nif"; break;
            case 2 : sortBy = "telefone"; break;
        }

        Page<Entidade> contactsPage = Entidade.findAll(empresa.id, filter, order, sortBy, pageSize, page);
        Integer iTotalDisplayRecords = contactsPage.getTotalRowCount();

        ObjectNode result = Json.newObject();
        result.put("sEcho", Integer.valueOf(params.get("sEcho")[0]));
        result.put("iTotalRecords", iTotalRecords);
        result.put("iTotalDisplayRecords", iTotalDisplayRecords);
        ArrayNode an = result.putArray("aaData");
        for(Entidade ent : contactsPage.getList()) {
            ObjectNode row = Json.newObject();
            row.put("0", ent.id);
            row.put("1", ent.nome);
            row.put("2", morada);
            an.add(row);
        }
        return ok(result);
    }

模型

我的Ebean查询:

public static Page<Entidade> findAll(int id_empresa, String filter, String order, String sortBy, int pageSize, int page){
  return find.where().eq("enabled", true).eq("empresa.id", id_empresa)
         .where().or(Expr.ilike("nome", "%" + filter + "%"), Expr.or(Expr.ilike("nif", "%" + filter + "%"), Expr.ilike("tipo.id", "%" + filter + "%")))
         .orderBy(sortBy + " " + order + ", nome " + order)
         .findPagingList(pageSize).setFetchAhead(false)
         .getPage(page);
    }

如何使我的过滤器成为一个或多个复选框的返回值?

0 个答案:

没有答案