Jquery 数据表插件 - sAjaxSource
我从 asp.net Web 服务获取数据,我想知道是否有办法将该数据(直接从 Web 服务以 json 格式)传递到 DataTables 对象中。我想做这样的事情:
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost/WebService/GetData",
} );
} );
I get my data from the asp.net web service and I was wondering whether there is a way to pass on that data (in json formar straight from the web service) into the DataTables object. I would like to do something like:
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost/WebService/GetData",
} );
} );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,你可以这样做。这是你的意思吗?...将数据传递到服务器?
Yes you can do that. Is this what you mean?... pass a data to a server?
您可以在这里找到一篇关于在 ASP.NET MVC 中使用 DataTables 的文章 集成 jQuery DataTables使用 ASP.NET MVC。
希望这可以帮助你。几乎没有什么可以帮助您(用于访问 DataTables 参数的模型类和用于直接序列化 JSON 的类)。它使代码变得更干净一些。
问候
Here you can find one article about using DataTables with ASP.NET MVC Integrating jQuery DataTables with ASP.NET MVC.
Hope this could help you. There are few thing that can help you (model class for accessing DataTables parameters and class for direct serialization int the JSON). It makes code little bit cleaner.
Regards
我现在正在做这件事。我正在使用 ASP.Net MVC 2 Web 应用程序,虔诚地使用数据表,并且需要在每个表上显示超过 1000 条记录。服务器端处理是我的选择。这就是我们所拥有的。
这是我们在视图 (/Admin/Unassigned) 中的声明。
这是我们的控制器函数(/Admin/UnassignedTable)。
笔记!!!!!!!添加控件时,您必须将控件值的引号设置为 \\",因为反斜杠需要位于 JSON 数据中。
希望在控制器中您可以访问您的 Web 服务。我对 Web 编程不太熟悉,所以我不知道你需要做什么,我只是认为这会有所帮助。
I'm working on this right now. I'm using ASP.Net MVC 2 Web Application, using the dataTables religiously, and need to show over 1000 records on each table. Server-Side processing was the way to go for me. Here's what we have.
Here's our declaration in the view (/Admin/Unassigned).
Here's our controller function (/Admin/UnassignedTable).
NOTE!!!!!!! When adding a control, you must put your quotes for your control values as \\" because the backslash needs to be in the JSON data.
Hopefully, in the controller you can access your webservice. I'm not too familiar with web programming, so I don't know what you'd need to do. I just thought this would help.
只要您的 Web 服务满足 DataTables API 约定,这是可能的。
看看 http://datatables.net/usage/server-side
更新
我已经按照您想要的方式在我的 ASP.NET MVC 应用程序中使用了 DataTables AjaxSource - 在初始化例程中指定它。然而,我的服务器端是专门设计的,以便数据表可以与之对话。
It is possible provided your web service satisfies DataTables API conventions.
Take a look at http://datatables.net/usage/server-side
UPDATE
I've used DataTables AjaxSource in my ASP.NET MVC application the way you want - specifying it in the initialization routine. However, my server side was specially designed so that DataTables could speak to it.
最后我自己整理了表格。它足以满足我现在相当小的目的。
I ended up composing the table by myself. It suffices for my purposes that are fairly minimal now.
是的。
创建一个将以正确格式存储数据表数据的对象。我使用了一个结构:
我们实际上为此创建了自己的序列化器,但概念是相同的。循环访问数据源并填充对象,然后将其序列化并响应:
这应该序列化为您需要的确切格式。如果您需要按特定顺序添加数据,则需要修改循环。请记住,{Passed In} 是传递到函数或直接分配给请求中的这些变量的值。
Yes.
Create an object that would store the Datatables data in the correct format. I used a structure:
We actually created our own Serializer for this, but the concept is the same. Loop through your data source and populate the object, then serialize it and respond:
That should serialize to the exact format you need. If you need to add data in a specific order, then you'll need to modify the loop. Keep in mind that the {Passed In} is the values being passed into a function or directly assigned to those variables from the request.