简体   繁体   English

将google.visualization.datatable与checkbox和KnockOut数据绑定相结合

[英]Combining google.visualization.datatable with checkbox and KnockOut data-bind

I'm in the process of converting my 'normal' HTML tables into Google's DataTable. 我正在将“普通”HTML表格转换为Google的DataTable。 Mostly because it will give me fixed headers and sorting. 主要是因为它会给我固定标题和排序。 Thanks to Creating advanced KnockOut binding handler for google.visualization.datatable I managed to create a KnockOut binding handler for the DataTable. 感谢为google.visualization.datatable创建高级KnockOut绑定处理程序,我设法为DataTable创建了一个KnockOut绑定处理程序。 This works great for read-only data. 这对于只读数据非常有用

Now I want to convert a table which has aa checkbox and a input textbox in every row. 现在我想转换一个在每一行都有一个复选框和一个输入文本框的表。 Creating these form elements isn't the problem but I use KnockOut data-bind on them. 创建这些表单元素不是问题,但我在它们上使用KnockOut数据绑定。 How to add these data-binding to my datatable? 如何将这些数据绑定添加到我的数据表中? I tried this: 我试过这个:

data.setCell(
    0, 0, "<input type='checkbox' data-bind=checked: ' " + order.inOrder + "'/>"
);

and

data.setCell(
    0, 0, "<input type='checkbox' data-bind=checked: order.inOrder />"
);

But both don't work. 但两者都不起作用。 Of course I tried using Google to find an answer but so far no luck. 当然我尝试使用谷歌找到答案,但到目前为止还没有运气。

Edit: Some more background info: We have a rather complicated page which gets some data from the server using AJAX and populating the table. 编辑:更多背景信息:我们有一个相当复杂的页面,它使用AJAX从服务器获取一些数据并填充表格。 We also use RequireJS, although the Google.Visualization part is outside RequireJS, because I'm having trouble getting it integrated ;) 我们也使用RequireJS,虽然Google.Visualization部分在RequireJS之外,因为我无法将其集成;)

The page is part of a wizard for an order system and the checkbox is the 'don't order' and the input box is to fill in the stock. 该页面是订单系统向导的一部分,复选框是“不订购”,输入框用于填写库存。 The table is: 该表是:

checkbox|Product name|amount|input box for stock|amount minus stock|price

The Next button needs to save the whole table, including the (updated) values for the checkbox and stock. “下一步”按钮需要保存整个表格,包括复选框和库存的(更新)值。

don't think data binding is going to work with Google charts 不要认为数据绑定适用于Google图表

even if it would, don't see much benefit, since you need to load the DataTable manually anyway 即使它会,也看不到多少好处,因为无论如何你需要手动加载DataTable

as such, just supply the value needed while loading the DataTable, 因此,只需在加载DataTable时提供所需的值,
something like... 就像是...
data.setCell(0, 0, "<input type='checkbox' " + ((order.inOrder === true) ? "checked" : "") + "/>");

other thoughts... 其他想法...

if the table chart uses paging buttons, only the rows for the current page are rendered, so binding would have to somehow occur on each 'page' event 如果表格图表使用分页按钮,则只渲染当前页面的行,因此必须以某种方式在每个'page'事件上进行绑定

using a checkbox input within the table chart will cause the 'select' event to fire on the table row when it is clicked 使用表格图表中的复选框输入将导致'select'事件在单击表格行时触发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM