【发布时间】:2017-01-14 06:39:34
【问题描述】:
我正在尝试为表格创建内联编辑(类似于angular-xeditable),但我希望一次只允许编辑一行。目前您可以将任意数量的行置于编辑模式。
选项
将行列表保持在编辑模式,一旦选择要编辑的新行,循环遍历列表并强制退出编辑模式,将请求行置于编辑模式并将其添加到名单。这基本上允许列表中最多有 1 行,导致一次可编辑一行。但我没有说明如何让行退出编辑模式。
有一个退出编辑模式的取消按钮。所以也许使用jquery(或angular.element)来获取所有取消按钮的列表并务实地点击它们 - 再次,在编辑模式下强制退出行,但这可能会减慢大表的速度,因为它将点击取消甚至不在编辑模式下的行。
<table class="table table-striped">
<thead>
<tr>
<th id="th-name">Name</th>
<th id="th-age">Age</th>
<th id="th-actions">Actions</th>
</tr>
</thead>
<tr ng-repeat="contact in model.contacts">
<td>
<span ng-show="edit != true">{{contact.name}}</span>
<input ng-show="edit" type="text" ng-model="model.selected.name" class="form-control" placeholder="Name">
</td>
<td>
<span ng-show="edit != true">{{contact.age}}</span>
<input ng-show="edit" type="text" ng-model="model.selected.age" class="form-control" placeholder="Name"></td>
<td>
<button ng-show="edit != true" id="table-edit" ng-click="edit = true; editContact(contact)" uib-tooltip="Delete" tooltip-trigger="mouseenter" tooltip-placement="bottom"><i class="fa fa-fw fa-pencil"></i></button>
<button ng-show="edit" id="table-save" ng-click="edit = false; saveContact($index)" uib-tooltip="Delete" tooltip-trigger="mouseenter" tooltip-placement="bottom"><i class="fa fa-fw fa-floppy-o"></i></button>
<button ng-show="edit" id="table-cancel" ng-click="edit = false; reset()" uib-tooltip="Delete" tooltip-trigger="mouseenter" tooltip-placement="bottom"><i class="fa fa-fw fa-trash"></i></button>
</td>
</tr>
</table>
这是一个 plunker 演示(允许所有行处于编辑模式):Plnkr Demo`
这是我想要实现的工作演示,但它使用模板。它根据我的喜好多次调用 getTemplate(每次运行摘要时调用它 - 单击按钮、键入、显示工具提示)。 Working Demo (Using templates)
【问题讨论】:
标签: javascript css angularjs html-table inline-editing