ExcelのようにGrailsオートフィルターに実装しようとしています。私の考えは Taglib を作成することです
class FilterPanelTagLib {
static namespace = 'x'
def filterPanel = {attrs, body ->
StringBuffer content = new StringBuffer()
List lines = attrs.lines
def filter = attrs.filter
out << "<form>"
long start = System.currentTimeMillis()
attrs.columns.each{col->
if(col != ''){
List tmp = getColumnValues(lines,col)
def value = filter?filter[col]:""
out << "<th>" + g.select(
onchange:"submit()",
name:"filter."+col,
from:tmp,
value:value,
noSelection:['ALL':'ALL'])+"</th>"
}else {
out << "<th> </th>"
}
}
out << "</form>"
println ((System.currentTimeMillis()-start)/1000 + " filterPanelTagLib".center(40,"-"))
}
private List getColumnValues(List lines, String column){
List result = lines.collect{it[column]}.unique().sort() << 'ALL'
return result
}
次のように GSP で使用します。
<x:filterPanel filter="${filter}" lines="${taskList}" columns="['id',
'label',
'activity',
'assignee'
'',
'']"/>
それは正常に動作します。選択したドロップボックスの値をコントローラーの params.filter として取得し、criteriaBuilder を使用してフィルター処理されたリストを取得できます。
問題は、各ドロップダウンのコンテンツを作成するパフォーマンスです。1000 項目のリストでテストしたところ、約 3 秒かかりました。目標パフォーマンスは 30.000 で 2 秒未満です
どんな提案でも大歓迎です!