2011-07-12 13 views
11

प्राइमफ़ेस डेटाटेबल आपको फ़िल्टर फ़िल्टर मैचमोड का उपयोग करके फ़िल्टरिंग प्रकार को कॉलम के लिए उपयोग करने देता है।यह प्राइमफ़ेस डेटाटेबल से फ़िल्टर मैचमोड कैसे काम करता है?

फिर भी, यदि आप LazyDataModel का उपयोग करते हैं तो आपको अपनी खोज विधि को लागू करना होगा, जो उस संपत्ति को बिल्कुल प्राप्त नहीं करता है। क्या यह सुविधा केवल सामान्य डेटा मॉडल के लिए उपयोगी है?

+0

GitHub मुद्दा: https://github.com/primefaces/primefaces/issues/30 – lazlev

उत्तर

12

वर्तमान में यह सुविधा LazyDataModel आउट-ऑफ-बॉक्स के लिए समर्थित नहीं है, हालांकि आप अभी भी अपेक्षाकृत कम प्रयास के साथ इसका उपयोग कर सकते हैं। blemasleposted प्राइमफ़ेस फ़ोरम पर संबंधित पैच, दुर्भाग्य से डेवलपर्स से अभी भी कोई प्रतिक्रिया नहीं है।

यदि आप गैर कोड-आक्रामक समाधान का उपयोग करना चाहते हैं, तो आप मेरा प्रयास कर सकते हैं।

/** 
* @param tableExpr expression, starting from the view root, 
*  which identifies the datatable to retrieve information from 
* @return map, containing pairs of {@code <filtered field id, match mode>}. 
*   Filtered field id is evaluated from the 'filterBy' 
*   attribute of the column in the following way: 
*   #{item.name} -> name 
*   #{item.category.name} -> category.name 
*/ 
public Map<String, FilterMatchMode> getFiltersMatchMode(String tableSearchExpr) { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    Object component = context.getViewRoot().findComponent(tableSearchExpr); 

    if (null == component) { 
     throw new IllegalArgumentException(
        "No component found for search expression: " 
          + tableSearchExpr); 
    } 
    if (!(component instanceof DataTable)) { 
     throw new IllegalArgumentException(
        "Component is not a DataTable: " + tableSearchExpr); 
    } 

    DataTable table = (DataTable) component; 
    Map<String, FilterMatchMode> constraints = 
      new HashMap<String, FilterMatchMode>(table.getColumns().size()); 

    for (Column column : table.getColumns()) { 
     ValueExpression filterExpression = 
        column.getValueExpression("filterBy"); 
     if (null != filterExpression) { 
      String filterExpressionString = filterExpression. 
                getExpressionString(); 
      //evaluating filtered field id 
      String filteredField = filterExpressionString.substring(
        filterExpressionString.indexOf('.') + 1, 
        filterExpressionString.indexOf('}')); 

      FilterMatchMode matchMode = 
        FilterMatchMode.fromUiParam(column.getFilterMatchMode()); 

      constraints.put(filteredField, matchMode); 
     } 
    } 

    return constraints; 
} 

कहाँ FilterMatchMode है:

public enum FilterMatchMode { 

STARTS_WITH("startsWith"), ENDS_WITH("endsWith"), 
CONTAINS("contains"), EXACT("exact"); 

/** 
* Value of p:column's filterMatchMode attribute 
*  which corresponds to this math mode 
*/ 
private final String uiParam; 

FilterMatchMode(String uiParam) { 
    this.uiParam = uiParam; 
} 

/** 
* @param uiParam value of p:column's filterMatchMode attribute 
* @return MatchMode which corresponds to given UI parameter 
* @throws IllegalArgumentException if no MatchMode 
*   is corresponding to given UI parameter 
*/ 
public static FilterMatchMode fromUiParam(String uiParam) { 
    for (FilterMatchMode matchMode : values()) { 
     if (matchMode.uiParam.equals(uiParam)) { 
      return matchMode; 
     } 
    } 
    throw new IllegalArgumentException("No MatchMode found for " + uiParam); 
} 

} 
+0

कहाँ डाल '

फ़िल्टर बाधाओं के साथ प्राप्त कर रहे हैं getFiltersMatchMode' विधि? – senyor

+0

@senyor इसे अपने 'LazyDataModel'' लोड() 'विधि कार्यान्वयन में उपयोग करें। – Micer

संबंधित मुद्दे