Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.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
Javascript 我可以使用primefaces 4.0实现冻结列吗_Javascript_Jquery_Jsf_Primefaces - Fatal编程技术网

Javascript 我可以使用primefaces 4.0实现冻结列吗

Javascript 我可以使用primefaces 4.0实现冻结列吗,javascript,jquery,jsf,primefaces,Javascript,Jquery,Jsf,Primefaces,您好,我想在**p:datatable中使用primefaces 4.0实现冻结列,但它不起作用。有人能告诉我哪里做错了吗。下面是我的代码** 我使用下面的链接在我的代码中实现了它,但它不适合我 提前谢谢 group.xhtml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="

您好,我想在**p:datatable中使用primefaces 4.0实现冻结列,但它不起作用。有人能告诉我哪里做错了吗。下面是我的代码** 我使用下面的链接在我的代码中实现了它,但它不适合我

提前谢谢

group.xhtml

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xml:lang="en"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:p="http://primefaces.org/ui">
          <h:head>
        <h:outputStylesheet library="css" name="table-style.css"  />
        <script type="text/javascript">
            jQuery(function() {
                jQuery('.ui-datatable tbody').sortable();
            });
            var oTable2 = $(primfacesDataTableId).find('table').dataTable({
                "sScrollX" : "100%", //Scroll
                "sScrollY" : "180",
                "bAutoWidth" : false,
                "bScrollCollapse" : true,
                "bPaginate" : false,
                "bSort" : false,
                "sInfo" : "",
                "sInfoEmpty" : ""
            });

var oFC = new FixedColumns(oTable2, {
                    "iLeftColumns" : 4, //Freezed first for columns
                    "sHeightMatch" : "auto",
                    "iLeftWidth" : 405
                });
        </script>
    </h:head>
    <p:dataTable id="primfacesDataTableId" var="sale" value="#{dtGroupView.sales}" scrollable="true" style="width: 250%">
        <f:facet name="header">
            Sales/Profits of Manufacturers
        </f:facet>

        <p:columnGroup type="header">
            <p:row>
                <p:column rowspan="3" headerText="Manufacturer"/>
                <p:column colspan="7" headerText="Sale Rate" />
            </p:row>
            <p:row>
                <p:column colspan="2" headerText="Sales" />
                <p:column colspan="2" headerText="Profit" />
            </p:row>
            <p:row>
                <p:column headerText="Last Year" sortBy="lastYearProfit"/>
                <p:column headerText="This Year" />
                <p:column headerText="Last Year" />
                <p:column headerText="This Year" />
                <p:column headerText="This Year1" />
                <p:column headerText="This Year2" />
                <p:column headerText="This Year3" />
            </p:row>
        </p:columnGroup>

        <p:column >
            <h:outputText value="#{sale.manufacturer}" />
        </p:column>
        <p:column  sortBy="#{sale.lastYearProfit}">
            <h:outputText value="#{sale.lastYearProfit}%" />
        </p:column>
        <p:column sortBy="#{sale.thisYearProfit}%">
            <h:outputText value="#{sale.thisYearProfit}%" />
        </p:column>
        <p:column sortBy="#{sale.lastYearSale}">
            <h:outputText value="#{sale.lastYearSale}">
                <f:convertNumber type="currency" currencySymbol="$" />
            </h:outputText>
        </p:column>
        <p:column sortBy="#{sale.thisYearSale}">
            <h:outputText value="#{sale.thisYearSale}">
                <f:convertNumber type="currency" currencySymbol="$" />
            </h:outputText>
        </p:column>
        <p:column  sortBy="#{sale.lastYearProfit}">
            <h:outputText value="#{sale.lastYearProfit}%" />
        </p:column>
        <p:column sortBy="#{sale.thisYearProfit}%">
            <h:outputText value="#{sale.thisYearProfit}%" />
        </p:column>
        <p:column sortBy="#{sale.lastYearSale}">
            <h:outputText value="#{sale.lastYearSale}">
                <f:convertNumber type="currency" currencySymbol="$" />
            </h:outputText>
        </p:column>

        <p:columnGroup type="footer">
            <p:row>
                <p:column colspan="3" style="text-align:right" footerText="Totals:" />
                <p:column footerText="$#{dtGroupView.lastYearTotal}" />

                <p:column footerText="$#{dtGroupView.thisYearTotal}" />
            </p:row>
        </p:columnGroup>

        <f:facet name="footer">
            Data between 2013-2014
        </f:facet>
    </p:dataTable>
</html>

GroupView.java

package org.primefaces.showcase.view.data.datatable;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.showcase.domain.Player;
import org.primefaces.showcase.domain.Sale;

@ManagedBean(name="dtGroupView")
@ViewScoped
public class GroupView implements Serializable {

    private final static String[] manufacturers;
    private List<Sale> sales;

    private final static String[] playerNames;
    private List<Integer> years;
    private List<Player> players;

    static {        
        manufacturers = new String[10];
        manufacturers[0] = "Apple";
        manufacturers[1] = "Samsung";
        manufacturers[2] = "Microsoft";
        manufacturers[3] = "Philips";
        manufacturers[4] = "Sony";
        manufacturers[5] = "LG";
        manufacturers[6] = "Sharp";
        manufacturers[7] = "Panasonic";
        manufacturers[8] = "HTC";
        manufacturers[9] = "Nokia";
    }

    static {
        playerNames = new String[10];
        playerNames[0] = "Lionel Messi";
        playerNames[1] = "Cristiano Ronaldo";
        playerNames[2] = "Arjen Robben";
        playerNames[3] = "Franck Ribery";
        playerNames[4] = "Ronaldinho";
        playerNames[5] = "Luis Suarez";
        playerNames[6] = "Sergio Aguero";
        playerNames[7] = "Zlatan Ibrahimovic";
        playerNames[8] = "Neymar Jr";
        playerNames[9] = "Andres Iniesta";
    }

    @PostConstruct
    public void init() {
        sales = new ArrayList<Sale>();
        for(int i = 0; i < 10; i++) {
            sales.add(new Sale(manufacturers[i], getRandomAmount(), getRandomAmount(), getRandomPercentage(), getRandomPercentage()));
        }

        years = new ArrayList<Integer>();
        years.add(2010);
        years.add(2011);
        years.add(2012);
        years.add(2013);
        years.add(2014);

        players = new ArrayList<Player>();
        for(int i = 0; i < 10; i++) {
            players.add(new Player(playerNames[i], generateRandomGoalStatsData()));
        }
    }

    public List<Sale> getSales() {
        return sales;
    }

    private int getRandomAmount() {
        return (int) (Math.random() * 100000);
    }

    private int getRandomPercentage() {
        return (int) (Math.random() * 100);
    }

    public String getLastYearTotal() {
        int total = 0;

        for(Sale sale : getSales()) {
            total += sale.getLastYearSale();
        }

        return new DecimalFormat("###,###.###").format(total);
    }

    public String getThisYearTotal() {
        int total = 0;

        for(Sale sale : getSales()) {
            total += sale.getThisYearSale();
        }

        return new DecimalFormat("###,###.###").format(total);
    }

    public List<Integer> getYears() {
        return years;
    }

    public int getYearCount() {
        return years.size();
    }

    public List<Player> getPlayers() {
        return players;
    }

    private Map<Integer,Integer> generateRandomGoalStatsData() {
        Map<Integer,Integer> stats = new LinkedHashMap<Integer, Integer>();
        for (int i = 0; i < 5; i++) {
            stats.put(years.get(i), getRandomGoals());
        }

        return stats;
    }

    private int getRandomGoals() {
        return (int) (Math.random() * 50);
    }
}


Sale.java


package org.primefaces.showcase.domain;

import java.io.Serializable;

public class Sale implements Serializable {

    private String manufacturer;

    private int lastYearSale;

    private int thisYearSale;

    private int lastYearProfit;

    private int thisYearProfit;

    public Sale() {}

    public Sale(String manufacturer, int lastYearSale, int thisYearSale, int lastYearProfit, int thisYearProfit) {
        this.manufacturer = manufacturer;
        this.lastYearSale = lastYearSale;
        this.thisYearSale = thisYearSale;
        this.lastYearProfit = lastYearProfit;
        this.thisYearProfit = thisYearProfit;
    }

    public int getLastYearProfit() {
        return lastYearProfit;
    }

    public void setLastYearProfit(int lastYearProfit) {
        this.lastYearProfit = lastYearProfit;
    }

    public int getLastYearSale() {
        return lastYearSale;
    }

    public void setLastYearSale(int lastYearSale) {
        this.lastYearSale = lastYearSale;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public int getThisYearProfit() {
        return thisYearProfit;
    }

    public void setThisYearProfit(int thisYearProfit) {
        this.thisYearProfit = thisYearProfit;
    }

    public int getThisYearSale() {
        return thisYearSale;
    }

    public void setThisYearSale(int thisYearSale) {
        this.thisYearSale = thisYearSale;
    }
}

jQuery(函数(){
jQuery('.ui datatable tbody').sortable();
});
var oTable2=$(primfacesDataTableId).find('table').dataTable({
“sScrollX”:“100%,//滚动
“sScrollY”:“180”,
“bAutoWidth”:假,
“崩溃”:没错,
“bPaginate”:错误,
“bSort”:错误,
“信丰”:“信丰”,
“无罪”:
});
var oFC=新的固定柱(可旋转2{
“iLeftColumns”:4,//首先冻结列
“sHeightMatch”:“自动”,
“iLeftWidth”:405
});
制造商的销售额/利润
2013-2014年数据
GroupView.java
包org.primefaces.showcase.view.data.datatable;
导入java.io.Serializable;
导入java.text.DecimalFormat;
导入java.util.ArrayList;
导入java.util.LinkedHashMap;
导入java.util.List;
导入java.util.Map;
导入javax.annotation.PostConstruct;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.ViewScoped;
导入org.primefaces.showcase.domain.Player;
导入org.primefaces.showcase.domain.Sale;
@ManagedBean(name=“dtGroupView”)
@视域
公共类GroupView实现了可序列化{
私有最终静态字符串[]制造商;
私人清单销售;
私有最终静态字符串[]playerNames;
私人名单年;
私人名单玩家;
静态{
制造商=新字符串[10];
制造商[0]=“苹果”;
制造商[1]=“三星”;
制造商[2]=“微软”;
制造商[3]=“飞利浦”;
制造商[4]=“索尼”;
制造商[5]=“LG”;
制造商[6]=“夏普”;
制造商[7]=“松下”;
制造商[8]=“HTC”;
制造商[9]=“诺基亚”;
}
静止的{
playerNames=新字符串[10];
playerNames[0]=“莱昂内尔·梅西”;
球员姓名[1]=“克里斯蒂亚诺·罗纳尔多”;
playerNames[2]=“Arjen Robben”;
playerNames[3]=“Franck Ribery”;
球员名称[4]=“罗纳尔迪尼奥”;
playerNames[5]=“路易斯·苏亚雷斯”;
playerNames[6]=“Sergio Aguero”;
playerNames[7]=“兹拉坦·伊布拉希莫维奇”;
playerNames[8]=“Neymar Jr”;
playerNames[9]=“Andres Iniesta”;
}
@施工后
公共void init(){
sales=新的ArrayList();
对于(int i=0;i<10;i++){
添加(新销售(制造商[i]、getRandomAmount()、getRandomAmount()、getRandomPercentage()、getRandomPercentage());
}
年份=新阵列列表();
年份。添加(2010年);
年份。添加(2011年);
年份。增加(2012年);
年份。增加(2013年);
年份。增加(2014年);
players=newarraylist();
对于(int i=0;i<10;i++){
添加(新玩家(playerNames[i],generateRandomGoalStatsData());
}
}
公共列表getSales(){
退货;
}
私有int getRandomAmount(){
返回值(int)(Math.random()*100000);
}
private int getRandomPercentage(){
返回值(int)(Math.random()*100);
}
公共字符串getLastYearTotal(){
int-total=0;
用于(销售:getSales()){
合计+=销售。getLastYearSale();
}
返回新的十进制格式(“####,###.##.###”)。格式(总计);
}
公共字符串getThisYearTotal(){
int-total=0;
用于(销售:getSales()){
合计+=销售额。getThisYearSale();
}
返回新的十进制格式(“####,###.##.###”)。格式(总计);
}
公共列表(年){
回归年;
}
public int getYearCount(){
返回年份。大小();
}
公共列表getPlayers(){
返回球员;
}
私有映射生成器domGoalstatsData(){
Map stats=newlinkedhashmap();
对于(int i=0;i<5;i++){
stats.put(years.get(i),getRandomGoals());
}
返回统计;
}
private int getRandomGoals(){
返回值(int)(Math.random()*50);
}
}
Sale.java
包org.primefaces.showcase.domain;
导入java.io.Serializable;
公共类Sale实现了可序列化{
私人字符串制造商;
私人国际去年出售;
今年的私人拍卖;
私人利润;
私利;
公开销售({}
公开销售(字符串制造商、去年销售额、今年销售额、去年利润、今年利润){
这个。制造商=制造商;
this.lastYearSale=lastYearSale;
this.thisYearSale=thisYearSale;
this.lastYearProfit=lastYearProfit;
this.ThisYear利润=ThisYear利润;
}