2014-08-27 48 views
1

我需要有一個複選框下拉列表分組,並且組頭也應該是可選的。如果你選擇了組頭,則應該選擇該組下的所有孩子。我嘗試使用jquery ui dropdownchecklist進行分組,但組標題不可選。退房的圖片鏈接下方複選框下拉列表與JSF分組

http://i.stack.imgur.com/wbD7L.jpg

正如你看到,「時間表」非選擇。我需要'時間表'和'補充時間表'有一個複選框,如果你點擊它,所有的孩子必須被選中。

回答

0

我看你使用DDCL, 首先,你需要下載一個更新ui.dropdownchecklist.jshere (ui.dropdownchecklist with patch)。它已被修補了額外的groupItemChecksWholeGroup標籤。

您所需要做的就是設置groupItemChecksWholeGroup:true。

見下

代碼的代碼ManagedBean

public ArrayList<SelectItem> cars; 
SelectItemGroup g1=new SelectItemGroup("BMWs"); 
SelectItemGroup g2=new SelectItemGroup("Audi"); 
g1.setSelectItems(new SelectItem[]{new SelectItem("320D", "320D"),new SelectItem("520D","520D"),new SelectItem("620D","620D"),new SelectItem("720D","720D")}); 
g2.setSelectItems(new SelectItem[]{new SelectItem("A3","A3"),new SelectItem("A6","A6"),new SelectItem("Q3","Q3"),new SelectItem("Q5","Q5"),new SelectItem("Q7","Q7")}); 
cars = new ArrayList<SelectItem>(); 
cars.add(g1); 
cars.add(g2); 

下面是HTML文件中的代碼

<h:selectManyListbox id="s1" value=""> 
<f:selectItem id="item1" itemLabel="All" itemValue="1" /> 
<f:selectItems value="#{myBean.cars}" /> 

然後在你的HTML頭添加這個jQuery腳本

<script type="text/javascript"> 
$(document).ready(function() { 
    $("#s1").dropdownchecklist({ 
     firstItemChecksAll : true, 
     groupItemChecksWholeGroup : true, 
     width : 250 
    }); 
}); 

其結果將是

enter image description here

1

如何使用PrimeFaces樹與複選框?看看他們的展示例如

Tree - Selection - Checkbox

enter image description here

+0

謝謝丹尼爾。它肯定符合我的要求,只是我可以讓樹不可摺疊? – Sahil 2014-08-27 13:50:33

+0

不確定,但您可以查看他們的文檔... – Daniel 2014-08-27 13:57:31