Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqgrid java服务器端分页_Java_Javascript_Jakarta Ee_Jqgrid - Fatal编程技术网

jqgrid java服务器端分页

jqgrid java服务器端分页,java,javascript,jakarta-ee,jqgrid,Java,Javascript,Jakarta Ee,Jqgrid,我正在尝试将服务器端排序添加到我的网格中,因此我添加了以下内容: onPaging : function(which_button) { _$("#myGrid").setGridParam({datatype: "xml"}); _$("#myGrid").trigger('reloadGrid'); } 当我点击下一页按钮时,它会转到我的服务器并再次加载网格,因此我再次看到第一页的记录。我的问题是如何

我正在尝试将服务器端排序添加到我的网格中,因此我添加了以下内容:

onPaging : function(which_button) {
                 _$("#myGrid").setGridParam({datatype: "xml"});
                _$("#myGrid").trigger('reloadGrid');
            }
当我点击下一页按钮时,它会转到我的服务器并再次加载网格,因此我再次看到第一页的记录。我的问题是如何连接有关网格记录和服务器的数据?是否有服务器端分页的完整示例?为了获得下一页的当前记录,我还需要向服务器传递什么?我需要在我的网页上添加什么,在服务器页面上添加什么

任何帮助都将被告知


提前感谢。

请确认您正在进行服务器端排序还是服务器端分页。从这个问题中,我了解到您正试图通过单击网格中的next/prev按钮从服务器检索下一页数据。如果您的目标只是获取分页数据,那么下面的逻辑将有所帮助。如果您对服务器端排序+服务器端分页感兴趣,则需要遵循类似的方法

服务器端分页逻辑: 假设您总共有1000条记录,这些记录必须显示为每页50条记录。 我假设您在第一页显示记录时只提取前50条记录,然后单击“下一步”按钮,您希望从数据库检索网格中显示的下50条记录

您不需要onPaging:函数。只要设置paging:true就足够了

在带有getter和setter的java类中有以下变量

// Total pages
    private Integer total = 0;
     //get how many rows we want to have into the grid - rowNum attribute in the grid
    private Integer rows = 0;
    //Get the requested page. By default grid sets this to 1.
    private Integer page = 0;
    // All Record
    private Integer records = 0;
    // sorting order ascending or descending
    private String sord;
    // get index row - i.e. user click to sort
    private String sidx;
/**
     * @return the total
     */
    public Integer getTotal() {
        return total;
    }

    /**
     * @param total the total to set
     */
    public void setTotal(Integer total) {
        this.total = total;
    }

    /**
     * @return the rows
     */
    public Integer getRows() {
        return rows;
    }

    /**
     * @param rows the rows to set
     */
    public void setRows(Integer rows) {
        this.rows = rows;
    }

    /**
     * @return the page
     */
    public Integer getPage() {
        return page;
    }

    /**
     * @param page the page to set
     */
    public void setPage(Integer page) {
        this.page = page;
    }

    /**
     * @return the records
     */
    public Integer getRecords() {
        return records;
    }

    /**
     * @param records the records to set
     */
    public void setRecords(Integer records) {
        this.records = records;

        if(this.records > 0 && this.rows > 0){
            this.total = (int)Math.ceil((double) this.records/(double) this.rows);
        }else{
            this.total = 0;
        }
    }

    /**
     * @return the sord
     */
    public String getSord() {
        return sord;
    }

    /**
     * @param sord the sord to set
     */
    public void setSord(String sord) {
        this.sord = sord;
    }

    /**
     * @return the sidx
     */
    public String getSidx() {
        return sidx;
    }

    /**
     * @param sidx the sidx to set
     */
    public void setSidx(String sidx) {
        this.sidx = sidx;
    }
之后,您需要进行一些计算,以便根据检索到的记录设置网格的字段

//假设您总共有1000条记录。这应该是动态设置的。目前它被硬编码为1000

setRecords(1000);
// for first time when we have page=0, it should 
// be page =1;
// If last page is required and if page no crosses total count
                int displayCount = count/rows;
                int remainder = count%rows;
                page = (page<=displayCount?page:count==0?0:remainder==0?displayCount:displayCount+1);


                int to = (getRows() * getPage());
                int from = to - getRows();

                if (to > getRecords()) to = getRecords();

                if (from > to) {
                    from = 0;
                    page = 1;
                }

setTotal((int) Math.ceil((double) getRecords() / (double) getRows()));

                if(getTotal() == 0) page =0;
setRecords(1000);
//这是我们第一次使用page=0时,它应该
//be page=1;
//如果需要最后一页,并且如果第0页与总计数交叉
int displayCount=计数/行;
整数余数=计数%行;
page=(page getRecords())到=getRecords();
如果(从>到){
from=0;
page=1;
}
setTotal((int)Math.ceil((double)getRecords()/(double)getRows());
如果(getTotal()==0)page=0;

请确认您正在进行服务器端排序还是服务器端分页。从这个问题中,我了解到您正试图通过单击网格中的next/prev按钮从服务器检索下一页数据。如果您的目标只是获取分页数据,那么下面的逻辑将有所帮助。如果您对服务器端排序+服务器端分页感兴趣,则需要遵循类似的方法

服务器端分页逻辑: 假设您总共有1000条记录,这些记录必须显示为每页50条记录。 我假设您在第一页显示记录时只提取前50条记录,然后单击“下一步”按钮,您希望从数据库检索网格中显示的下50条记录

您不需要onPaging:函数。只要设置paging:true就足够了

在带有getter和setter的java类中有以下变量

// Total pages
    private Integer total = 0;
     //get how many rows we want to have into the grid - rowNum attribute in the grid
    private Integer rows = 0;
    //Get the requested page. By default grid sets this to 1.
    private Integer page = 0;
    // All Record
    private Integer records = 0;
    // sorting order ascending or descending
    private String sord;
    // get index row - i.e. user click to sort
    private String sidx;
/**
     * @return the total
     */
    public Integer getTotal() {
        return total;
    }

    /**
     * @param total the total to set
     */
    public void setTotal(Integer total) {
        this.total = total;
    }

    /**
     * @return the rows
     */
    public Integer getRows() {
        return rows;
    }

    /**
     * @param rows the rows to set
     */
    public void setRows(Integer rows) {
        this.rows = rows;
    }

    /**
     * @return the page
     */
    public Integer getPage() {
        return page;
    }

    /**
     * @param page the page to set
     */
    public void setPage(Integer page) {
        this.page = page;
    }

    /**
     * @return the records
     */
    public Integer getRecords() {
        return records;
    }

    /**
     * @param records the records to set
     */
    public void setRecords(Integer records) {
        this.records = records;

        if(this.records > 0 && this.rows > 0){
            this.total = (int)Math.ceil((double) this.records/(double) this.rows);
        }else{
            this.total = 0;
        }
    }

    /**
     * @return the sord
     */
    public String getSord() {
        return sord;
    }

    /**
     * @param sord the sord to set
     */
    public void setSord(String sord) {
        this.sord = sord;
    }

    /**
     * @return the sidx
     */
    public String getSidx() {
        return sidx;
    }

    /**
     * @param sidx the sidx to set
     */
    public void setSidx(String sidx) {
        this.sidx = sidx;
    }
之后,您需要进行一些计算,以便根据检索到的记录设置网格的字段

//假设您总共有1000条记录。这应该是动态设置的。目前它被硬编码为1000

setRecords(1000);
// for first time when we have page=0, it should 
// be page =1;
// If last page is required and if page no crosses total count
                int displayCount = count/rows;
                int remainder = count%rows;
                page = (page<=displayCount?page:count==0?0:remainder==0?displayCount:displayCount+1);


                int to = (getRows() * getPage());
                int from = to - getRows();

                if (to > getRecords()) to = getRecords();

                if (from > to) {
                    from = 0;
                    page = 1;
                }

setTotal((int) Math.ceil((double) getRecords() / (double) getRows()));

                if(getTotal() == 0) page =0;
setRecords(1000);
//这是我们第一次使用page=0时,它应该
//be page=1;
//如果需要最后一页,并且如果第0页与总计数交叉
int displayCount=计数/行;
整数余数=计数%行;
page=(page getRecords())到=getRecords();
如果(从>到){
from=0;
page=1;
}
setTotal((int)Math.ceil((double)getRecords()/(double)getRows());
如果(getTotal()==0)page=0;

谢谢您的回答!我要试一试。正如您所理解的,我希望有服务器端分页和客户端排序。我应该将服务器端的变量添加到jqrid吗?或者当我单击next/prev按钮时,这些值会自动从jqgrid传递到服务器端?再次感谢。因为您希望实现服务器端分页,所以为了对网格进行排序,您需要从服务器中提取剩余的数据。因此,客户端排序将不起作用。您必须在数据库查询中使用动态ORDERBY子句来为您的结果集排序。如果(sidx!=null&&!sidx.equals(“”){setOrderByField(sortMap.get(sidx));setOrderBy(sord);}或者{//如果未选择排序,则按默认顺序执行。setOrderByField(“employeeId”);setOrderBy(desc);}您需要设置属性文件或静态映射,以将网格列名映射到数据库列名。此外,所有与排序或分页相关的变量默认都存在于网格中,因此您不需要在网格外部指定它们。请提供完整的代码好吗?i、 服务器端和客户端。谢谢您的回答!我要试一试。正如您所理解的,我希望有服务器端分页和客户端排序。我应该将服务器端的变量添加到jqrid吗?或者当我单击next/prev按钮时,这些值会自动从jqgrid传递到服务器端?再次感谢。因为您希望实现服务器端分页,所以为了对网格进行排序,您需要从服务器中提取剩余的数据。因此,客户端排序将不起作用。您必须在数据库查询中使用动态ORDERBY子句来为您的结果集排序。如果(sidx!=null&&!sidx.equals(“”){setOrderByField(sortMap.get(sidx));setOrderBy(sord);}或者{//如果未选择排序,则执行默认ord,则可以使用类似的方法