p:datatable中的filter不进行筛选,而是不显示任何内容



为了处理动态列表和动态html,我在数据表中构建了一个带有动态列的动态表,一切都很好,可以按要求工作,只是它不过滤,而是显示没有记录,因为键入了一些文本。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

@ManagedBean(name="liveRangeService", eager = true)
@ApplicationScoped
public class LiveRangeService implements Serializable {
ResultSet RS;
dbConnectionSQLServer db;
private List< Map<String, ColumnModel> > tableData;
private Map<String, ColumnModel> selectedData;
private List< Map<String, ColumnModel> > filteredData;
public Map<String, ColumnModel> getSelectedData() {
return selectedData;
}
public void setSelectedData(Map<String, ColumnModel> selectedData) {
this.selectedData = selectedData;
}
private List<ColumnModel> tableHeaderNames;
private String tableColWidths;
private List< Map<String, ColumnModel> > selectedRow;
public List<Map<String, ColumnModel>> getTableData() {
return tableData;
}
public List<ColumnModel> getTableHeaderNames() {
return tableHeaderNames;
}
public LiveRangeService() {
}
public void LiveRangeServicesss() {
db = new dbConnectionSQLServer();
try {
tableData = new ArrayList< Map<String, ColumnModel> >();
tableHeaderNames = new ArrayList<ColumnModel>();
Statement SQL = dbConnectionSQLServer.getCN().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
RS = SQL.executeQuery("Select * From Coa32 Order BY Title");
for (int j = 0; j < RS.getMetaData().getColumnCount(); j++) {
tableHeaderNames.add(new ColumnModel("header "+j, RS.getMetaData().getColumnLabel(j+1)));
}
//Generate table data.
for (int i = 0; RS.next(); i++) {
Map<String, ColumnModel> playlist = new HashMap<String, ColumnModel>();
//                System.out.println("Row : " + i );
for (int j = 0; j < RS.getMetaData().getColumnCount(); j++) {
playlist.put(tableHeaderNames.get(j).key, new ColumnModel(tableHeaderNames.get(j).key, RS.getString(j+1)));
}
tableData.add(playlist);
}
PrimeFaces.current().ajax().update("form:dlgTBL");
PrimeFaces.current().ajax().update("form:dlgTBL2");
PrimeFaces.current().executeScript("PF('dlg').show();");
} catch (SQLException e) {
System.out.println("Error !!! " + e.getMessage());
}
}
public List<Map<String, ColumnModel>> getSelectedRow() {
try {System.out.println("Selected Row! " + selectedRow.size());} catch (Exception e) {}
return selectedRow;
}
public void setSelectedRow(List<Map<String, ColumnModel>> selectedRow) {
System.out.println( "selected size: " + selectedRow.size() );
this.selectedRow = selectedRow;
}
public String getTableColWidths() {
return tableColWidths;
}
public void setTableColWidths(String tableColWidths) {
this.tableColWidths = tableColWidths;
}
public List<Map<String, ColumnModel>> getFilteredData() {
return filteredData;
}
public void setFilteredData(List<Map<String, ColumnModel>> filteredData) {
this.filteredData = filteredData;
}
}

以下是html部分

<p:dialog id="dlgTBL" modal="true" showEffect="bounce" widgetVar="dlg" resizable="false">
<p:dataTable var="result" id="tbl" widgetVar="dtlTBL"
value="#{liveRangeService.tableData}" 
paginator="false"
scrollable="true"  rowIndexVar="index"  scrollHeight="500" 
scrollRows="50" liveScroll="true"
filterDelay="1100"
>
<p:ajax event="rowSelect" listener="#{indexBean.onRowSelect}"  />
<f:facet name="header">
<p:outputPanel layout="inline" styleClass="tabSpacer">
<h:outputText value="Global Filter:" />
<p:inputText id="globalFilter" onkeyup="PF('dtlTBL').filter()" style="width:150px;margin-left:10px;"/>
</p:outputPanel>
</f:facet>
<p:column width="10">
<f:facet name="header">
<h:outputText value="Sr." />
</f:facet>
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:columns value="#{liveRangeService.tableHeaderNames}"
var="mycolHeader" 
width="#{colIndex==0?'10%':colIndex==1?'70%':colIndex==2?'10%':colIndex==3?'10%':'0'}" 
columnIndexVar="colIndex" selectRow="true"
sortBy="#{result[mycolHeader.value]}"
filterBy="#{result[mycolHeader.value]}"
filterMatchMode="contains"                        
>
<f:facet name="header">
<h:outputText value="#{mycolHeader.value}" />
</f:facet>
<h:outputText value="#{result[mycolHeader.key].value}" />
<br />
</p:columns>
</p:dataTable>
</p:dialog>

请告知代码的更改。

乍一看,这可能是设置sortBy和filterBy属性的方式。

var="result"

是Map的一个实例,如果我没有看错的话。

"#{result[mycolHeader.value]}"

有一个问题,您使用.value而不是.key。如果您使用.key,它仍然会返回ColumnModel,如果我没有弄错的话。因此,设置过滤器的方法是,如果从映射中找到ColumnModel实例,则放入过滤器中的文本将与该实例相匹配。

希望我能正确阅读代码,因为它有点令人困惑。尤其是将ColumnModel用作(String,String(元组,而不仅仅是它的预期用途。我认为你可以从更改表格数据的类型

List<Map<String,ColumnModel>>

List<Map<String,String>>

因为您似乎没有同时使用ColumnModel的两个字段。

最新更新