如何仅从给定行的表列中插入数据? [英] how to insert data from table columns of the given row only?

查看:87
本文介绍了如何仅从给定行的表列中插入数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,看起来像这样

I have a data table which looks like this

到目前为止, p>

My table so far is

<table id="example1" class="table table-bordered table-striped">
    <thead>

        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Age</th>
            <th>Sex</th>
            <th>District</th>
            <th>VDC/MUNICIPAL</th>
            <th>Ward No.</th>
            <th>Camp Visited?</th>
            <th>Consense</th>
            <th>Status</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="persons : ${part}">
            <form method="post" th:action="@{/addReport}" enctype="multipart/form-data">
                <input type="hidden" value="th:text='${ persons.name}'">
                <td contenteditable='true' th:text="${persons.name}"></td>
                <td contenteditable='true' th:text="${persons.lastName}"></td>
                <td contenteditable='true' th:text="${persons.age}"></td>
                <td contenteditable='true' th:text="${persons.sex}"> </td>
                <td contenteditable='true' th:text="${persons.district}"></td>
                <td contenteditable='true' th:text="${persons.vdcMun}"></td>
                <td contenteditable='true' th:text="${persons.wardNo}"></td>
                <td>
                    <div class="checkbox">
                        <input type='hidden' value='no' name='attendStatus'>
                        <label>
                            <input type="checkbox" value="yes" name="attendStatus">
                        </label>
                    </div>
                </td>
                <td>
                    <div class="form-control">
                        <input type="hidden" name="file" value="null">
                        <input id="file" type="file" name="file" accept="image/*">
                    </div>
                </td>
                <td>
                    <button type="submit" class="btn btn-success">Submit</button>
                </td>
                <input type="hidden" th:value="${persons.id}" name="id">
            </form>
        </tr>
    </tbody>
</table>

我已经使用 thymeleaf 列和它工作正常。此表成功保存数据,但现在我想添加编辑功能。所有表格列都是可编辑的,所以无论何时点击一列,我都可以对其进行编辑。编辑后的数据现在应该保存到我的数据库中。 (我不需要帮助来保存数据,例如后端)。我想传递编辑列(td)的值,如果它被编辑的话,通过只是传递值。

I have used thymeleaf to iterate data throughout the columns and it is working fine. this table successfully saves the data but now I want to add edit feature. all the table columns are editable so whenever I click on one column I can edit it. the edited data should now be saved into my database. (I don't need help to save data i.e back-end). I want to pass value of edit column(td) if it is edited else pass just pass the value as it is.

我该怎么做?任何JavaScript代码或想法都将受到欢迎。

How can I do so? any javascript code or ideas will be welcome.

推荐答案

在这种情况下,我们曾经有一个隐藏的参数,因为我看到你也有。 U只需要记住在数据库中自动生成的唯一标识的值。只需将这些值映射到每一行,将其用作标识符,当编辑发生时,U可以将编辑后的数据发送回来,以便根据编号识别要编辑的行。如果误解了你的问题,请原谅我。

In that case we used to have a hidden param as i see u have too . U just need to remember the value of unique Id that is auto generated in DB. Just map those values to each row , Use it as an identifier , When Editing happens U can send the Id back with the edited data so that you can identify which row to edit based on Id. Pardon me if misunderstood your questions.

这篇关于如何仅从给定行的表列中插入数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆