jQuery 如何更新引导表中的数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27902925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:28:26  来源:igfitidea点击:

how to update data in bootstrap table

jquerytwitter-bootstrap

提问by Noono

I have one bootstrap table with following code.

我有一个带有以下代码的引导表。

  <table id="tblPendingRequests" data-height="300">
       <thead>
          <tr>
             <th data-field="Version">Version</th>
             <th data-field="Env">Env</th>
             <th data-field="Release">Release</th>
             <th data-field="CreatedBy">Created By</th>
             <th data-field="Action">Action</th>
          </tr>
      </thead>
   </table>

added below references also.

还添加了以下参考资料。

<script src="~/Scripts/bootstrap-table.js"></script>
<link href="~/Content/bootstrap-table.min.css" rel="stylesheet" />

and my jquery code to load data

和我的 jquery 代码来加载数据

     function loadData()
     {
       $(function () {
        $('#tblPendingRequests').bootstrapTable({
        });
      });
     }

and then I am loading some data to this table. Like this:

然后我将一些数据加载到这个表中。像这样:

var mydata = { "Version": data[index].DeploymentName, "Env": data[index].EnvName, 
                  "Release":data[index].ReleaseName, "CreatedBy": data[index].UpdatedBy  "Action": ActionButton };
            testData.push(mydata);
      updateData(testData);
  function updateData(myData) {
     $('#tblPendingRequests').bootstrapTable("append", myData);

      }

It is diplaying the data properly. I have one project dropdown on the page. Onchange of the project name i want to populate this table with fresh data. It is not happening. It is appending data to existing table data which i don't want.

它正在正确显示数据。我在页面上有一个项目下拉列表。更改项目名称时,我想用新数据填充此表。它没有发生。它将数据附加到我不想要的现有表数据。

How to refresh the table and load new data in the table.

如何刷新表并在表中加载新数据。

采纳答案by Karlen Kishmiryan

Try to use the loadinstead of append.

尝试使用load代替append

From the official documentation

来自官方文档

append- Append the data to table.

load- Load the data to table, the old rows will be removed.

append- 将数据附加到表中。

load- 将数据加载到表中,旧行将被删除。

Also both functions accept the same argument data.

此外,两个函数都接受相同的参数data

回答by Ross Kerr

I destroy the table, $('#tblPendingRequests').bootstrapTable("destroy");and then reload the data, $('#tblPendingRequests').bootstrapTable({data: myFreshData});.

我销毁表,$('#tblPendingRequests').bootstrapTable("destroy");然后重新加载数据,$('#tblPendingRequests').bootstrapTable({data: myFreshData});

From a performance perspective it might not be as fast as getting loadto work, but it's fast enough that I've never noticed a switch over with up to 1,000 rows.

从性能的角度来看,它可能没有load开始工作那么快,但它足够快,我从未注意到多达 1,000 行的切换。

Update 10.4.2018Came back to bootstrap table this past month and loadis working for me as advertised now, so I'm no longer suggesting this workaround.

2018 年 4月 10 日更新在上个月回到引导表,并且load按照现在的宣传为我工作,所以我不再建议这种解决方法。