0

我正在使用敲除将行和列动态添加到表中,但进一步我需要通过拖放来重新排序列。下面是我的视图和模型。

看法:

    <table id="gridTable">
    <tr data-bind="foreach: activeColumns">
      <th data-bind="text: display"></th>
    </tr>
    <tbody id="sortable" data-bind="foreach: rows">
     <tr data-bind="foreach: $root.activeColumns">
         <td>
            <span  data-bind="visible: readonly, text: $parent[property]"></span>
            <input data-bind="visible: !readonly, value: $parent[property]"/>
          </td>
</tr>
</tbody>

模型:

rows: ko.observableArray([
new Person(1, "Bob", 44),
new Person(2, "Ted", 22),
new Person(3, "Jane", 55),
new Person(4, "Sue", 11)
]),
activeColumns: ko.observableArray([{property: 'id', display: 'ID', readonly: true},
{property: 'name', display: 'Name', readonly: false}, {property: 'age', display: 'Age',
readonly: false}]),
addColumn: function() {
    var newProperty = this.newAttribute();
    var newProperty1= this.selectedCategory();
    this.activeColumns.push({property: newProperty, display: newProperty, readonly: 
 false});
    ko.utils.arrayForEach(this.rows(), function(row) {
        if (!row[newProperty]) {
        row[newProperty] = ko.observable();
        }
    });
4

1 回答 1

0

使用 dragtable.js 解决了这个问题。使用以下链接

http://www.danvk.org/wp/dragtable/

于 2012-12-31T13:15:00.820 回答