简体   繁体   English

如何使用编辑窗口编辑表中的行

[英]How to edit row in a table with edit window

I have a problem. 我有个问题。 It is about edit selected row in a table. 它是关于编辑表中的选定行。 Each row in the table has at the end botton to edit self. 表格中的每一行都在末尾的botton中编辑自己。 If I click this button I can see edit window to edit selected data row from table. 如果单击此按钮,我将看到编辑窗口以编辑表中的选定数据行。 I am using Bootstrap and have a problem. 我正在使用Bootstrap并遇到问题。 How to get edit-window and after click save on edit window to replace selected row with new values?? 如何获得编辑窗口,然后在编辑窗口上单击“保存”以将所选行替换为新值?
It is best to look at my example! 最好看看我的例子!

This is my **DEMO 这是我的** DEMO

Button to add new row 按钮以添加新行

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  + Define a new visual feature
</button>

Table to add new row. 在表中添加新行。

    <table class="table table-striped" id="table-visual-features">
        <thead>
            <tr>
                <th>Visual Feature</th>
                <th>Type [currently not used]</th>
                <th>Description</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>

Here is a value, which one has in selected row in a table. 这是一个值,该值在表的选定行中具有。 This value I would like to edit using edit window using Bootstrap 我想使用Bootstrap在编辑窗口中编辑此值

    console.log($(this).closest('tr').children('td').eq(0).text());
    console.log($(this).closest('tr').children('td').eq(1).text());
    console.log($(this).closest('tr').children('td').eq(2).text())

You need a reference to the row you are going to edit. 您需要对要编辑的行的引用。 What you could do for instance, is something like this: 例如,您可以做的是这样的:

var $table = $('#table-visual-features');
$table.on('click', 'tbody tr button[data-target=#edit]', function (event) {
    var $rows = $table.find('tbody tr');
    var $thisRow = $(this).parents('tr').eq(0);
    var index = $rows.index($thisRow);
    // open your modal here; now you know which row to edit
});

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

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