- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试做这样的事情 https://datatables.net/blog/2012-05-31但是,我也在使用服务器端处理。
我的问题出在添加新行部分。
var t = $("#table").DataTable({
"ajax": "https://api.myjson.com/bins/2k6e5",
"serverSide": true,
"autoWidth": false,
"responsive": true,
"ordering": true,
"searching": true,
"paging": true,
"columns": [{
data: "Id"
}, {
data: "Name"
}, {
data: "Actived"
}]
});
var model = [{
"Id": 4,
"Name": "Name of the Object",
"Actived": true
}];
console.log(model);
t.rows.add(model).draw();
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.js"></script>
<table id="table" class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Actived</th>
</tr>
</thead>
<tbody></tbody>
</table>
var t = $("#tableRegistros").DataTable({
"ajax": "https://api.myjson.com/bins/2k6e5",
//"serverSide": true,
"autoWidth": false,
"responsive": true,
"ordering": true,
"searching": true,
"paging": true,
"columns": [{
data: "Id"
}, {
data: "Name"
}, {
data: "Actived"
}]
});
var model = [{
"Id": 4,
"Name": "Name of the Object",
"Actived": true
}];
console.log(model);
t.rows.add(model);
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.js"></script>
<table id="tableRegistros" class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Actived</th>
</tr>
</thead>
<tbody></tbody>
</table>
唯一的区别是服务器端选项。
最佳答案
TLDR;您不能使用 row.add()
与服务器端处理。阅读替代方案的答案。
不过要记住的一件事是添加一行 row.add()
仅将其添加到 JavaScript 中的表中(即在客户端);如果表格被刷新,数据将不会添加到 Ajax 源并且会消失。如果您希望能够在数据源中永久创建数据,则需要使用 Editor extension到 DataTables,不幸的是,它已获得许可并且不像其他 DataTables 那样免费(或编写您自己的服务器端 CRUD 处理程序)。
编辑:参见 server side documentation它说:
When using server-side processing, DataTables will make an Ajax request to the server for each draw of the information on the page (i.e. when paging, ordering, searching, etc.).
可能发生的情况是您的行被添加,然后表格被重新绘制,这向服务器发送了一个请求,但它没有找到任何数据,因此它没有显示任何数据。您添加的新行在技术上是添加的,但随后立即被覆盖。不幸的是,如果是这种情况,您将永远无法在使用服务器端处理时以这种方式添加行。
使用服务器端的全部意义在于,不让 DataTables 处理表中数据的操作,而是在服务器端处理,只允许 DataTables 显示数据。
编辑 2:(因为您要求提供更多详细信息)
参见 this forum post (关于您的确切问题)插件作者,他说:
When in server-side processing mode, the data store is at the server. So adding a row on the client-side (if you'll excuse me) is fairly pointless. DataTables in SSP mode is just a dumb display and events library. If you need to add a row, then you need to add it to the data source (i.e. at the server) and then just redraw the table.
通过使用服务器端处理,您放弃了在客户端使用 row.add()
在 JavaScript 中添加行的能力。
。如果你想让它们出现,你绝对必须在服务器端添加它们。这将要求您使用 Editor extension或者编写一些代码,将 Ajax PUT 或 POST 请求发送到您的服务器端,然后由服务器端处理程序来添加行。
编辑 3:您一直要求提供示例,但要求服务器端 CRUD 代码的示例基本上是要求某人为您编写整个后端(更不用说我们不知道您当前的后端是什么样子,甚至不知道它使用什么语言)。你现在问的是一个完全不同的问题。 Here is a link对于服务器端代码的要求和指南的文档,如果您想编写自己的代码(或者再次支付 Editor 并获得插件作者已经为您编写的后端) C# 或 PHP)。
关于javascript - DataTables row.add() 不适用于 serverSide 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38486228/
I have a question about adding files in git. I have found multiple stackoverflow questions about
我是 visual studio 的新手,来自 Delphi。 我有一个充满 .cs 文件的目录树(根是\Common)。 我还有一个充满应用程序的目录树(根目录是\Applications) 最后,
这个问题在这里已经有了答案: Array's lookup time complexity vs. how it is stored (4 个答案) Time complexity for java
谁能告诉我这两者有什么区别: ALTER TABLE x1 ADD INDEX(a); ALTER TABLE x1 ADD INDEX(b); 和 ALTER TABLE x1 ADD INDEX(
为什么有时我们使用 getChildren() add() 而其他时候我们直接使用 add() es: https://docs.oracle.com/javafx/2/get_started/for
如何使用 bootstrap css 在输入下方添加跨度?我需要做这样的事情: 最佳答案 是这样的吗? http://jsfiddle.net/swm53ran/205/ 您可以使用纯 CSS 来实现
问题 np.add(X, 2*Y, out=X) 比 np.add(X, Y, out=X); np.add(X, Y, out=X).使用 np.add(X, Y, out=X); 是一种实际做法吗
当我跑 git add --intent-to-add .所有未跟踪的文件将其状态从“未跟踪的文件”( git status -s 显示 ?? )更改为“未暂存以进行提交的更改”( git statu
我不知道 .add 之间有什么区别和 .sink.add ? 例子: StreamController myStreamController = StreamController(); stream
getContentPane().add() 和 add() 的意思一样吗? public class TestFrame extends JFrame{ public TestFrame()
git add . 和 git add * 会完成完全相同的事情吗? 最佳答案 不,不会。 * 是一个 glob 模式,不会匹配以 开头的文件。 例如,假设这是当前目录,我有 2 个新文件要添加 fo
git的分支与合并的两种方法 git add -A和 git add . git add -u在功能上看似很相近,但还是存在一点差别 git add . :他会
git add [--all | -A] 之间有什么区别?和 git add . ? 最佳答案 此答案仅适用于 Git 版本 1.x。对于 Git 版本 2.x,请参阅其他答案。 总结: git ad
我刚刚安装了最新的 Wix v3.7。我创建了一个 VS 2010“Excel 2010 加载项”项目,并在同一个解决方案中创建了一个 Wix“安装项目”。 问题是,当我尝试从 Wix 项目中引用 A
YUI.add 和 YUI().add 有什么区别? 最佳答案 在第一种情况下,您要注册一个模块可以加载到 YUI 沙箱中,在第二种情况下,您要构建一个沙箱,然后进行注册(这是一种非常不典型的用法)。
测试代码时,任何输入到列表中的值在按下“enter”后都会消失。 我对编程和网络开发非常陌生。请具体一点,以便我理解。 function addItem(){ var item = documen
我正在浏览 python 的 dis 包。我尝试了代码以查看它是如何工作的 >>> def get(): ... x=4 ... y=x+3 ............ this lin
我已经对我的文件夹进行了版本控制 git init git add . git commit -m 'Initial commit' 我应该怎么做 git add 对于我在 .? 中创建的每个新文件
当我执行 $ git add * 时,有时我意识到 git 不会将已删除的文件添加到舞台上,如果删除或添加它,我需要手动指示,但我想不通找出 $ git add --all 有什么区别。因此,如果星号
这个问题在这里已经有了答案: Difference between "git add -A" and "git add ." (12 个答案) 关闭 6 年前。 目前,当我想提交并将内容推送到远程
我是一名优秀的程序员,十分优秀!