Javascript 过滤d3后的排序表
所以我有一个表,它在一些输入中过滤keydown。然后我尝试对剩余的行进行排序。我已经尝试了很多方法,下面的尝试是基于这样一个想法:我用@rows上的内容创建一个表,然后尝试使用另一个选择对附加了主干模型的相同元素进行排序(出于其他原因,我需要有主干模型) 另外,使用上面的方法,我得到一个d3错误——不能调用null的insertBefore 此代码有什么问题/如何实现过滤数据的排序 更新-Javascript 过滤d3后的排序表,javascript,coffeescript,d3.js,Javascript,Coffeescript,D3.js,所以我有一个表,它在一些输入中过滤keydown。然后我尝试对剩余的行进行排序。我已经尝试了很多方法,下面的尝试是基于这样一个想法:我用@rows上的内容创建一个表,然后尝试使用另一个选择对附加了主干模型的相同元素进行排序(出于其他原因,我需要有主干模型) 另外,使用上面的方法,我得到一个d3错误——不能调用null的insertBefore 此代码有什么问题/如何实现过滤数据的排序 更新- 好的,我使用了调试器,当我使用调试器时,我注意到排序正在工作,但是,一旦我们到达click函数末尾的执行
好的,我使用了调试器,当我使用调试器时,我注意到排序正在工作,但是,一旦我们到达click函数末尾的执行点,整个表将以其原始形式重新呈现 呃,显然不是??当我添加内容时,我的html看起来很好。这似乎更像是我理解如何绑定数据的问题。您考虑过使用吗?这就是我正在做的-@currentlyDisplayedRows.sort(…在Callback的最终返回之后会出现奇怪的东西,但您只在单击时才这样做,而不是在我正确看到的情况下进行筛选?我是在单击表的标题时这样做的,因此在单击列标题时会进行排序,它应该对当前显示的行(在筛选之后存在的行)进行排序)
renderTable:()=>
@table = d3.select("#search-results-area").append("table").attr("id",@tableId).attr("class","visualization-panel")
@thead = @table.append("thead")
@tbody = @table.append("tbody")
@input = @table.append("input").attr("id",@inputId).on("keydown",(d)=>
toFilter = $(@input[0][0]).val()
window.setTimeout((()=>
toFilter = $(@input[0][0]).val()
@rows.filter((d)=>
return d
).remove()
@rows = @tbody.selectAll("tr").data(@collection.models).enter().append("tr")
@rows.filter((d)=>
if @filterFunc(toFilter,d)
return d
).selectAll("td").data((model)=>
return @columns.map((column)=>
return {column : column, val : model.get(column)}
)
).enter().append("td").text((d)=>
for column in @columns
if d.column == column
return d.val
)
# @currentlyDisplayedRows = @tbody.selectAll("tr").data(@collection.models.filter((d)=>
# console.log "TO FILTER"
# console.log toFilter
# if @filterFunc(toFilter,d)
# console.log d
# return d
# )).exit().remove()
@currentlyDisplayedRows = @tbody.selectAll("tr").data(@collection.models).filter((d)=>
if @filterFunc(toFilter,d)
return d
).remove()
),1000)
)
@columns = @json["Columns"]
@initializeSortingFunctionManager(@columns)
@thead.append("tr").selectAll("th").data(@columns).enter().append("th").text((col)-> return col).on("click",(d)=>
@currentlyDisplayedRows.sort((x,y)=>
xVal = x.get(d)
yVal = y.get(d)
func = @sortingFunctionManager[d](xVal,yVal)
return func
)
)
@tbody.selectAll("tr").attr("class","spacing center-text")
@renderTableBody()