Jquery DataTables warning : Requested unknown from the data source for row 0
昨天在做 Jquery DataTables 的时候,遇到的一个问题,我使用MVC,在tables上加入了一个actionlink的href。但是在运行起来的时候,报错:
DataTables warning: Requested unknown parameter '3' from the data source for row 0
通过search一下网上大神们的解决方法,所以我就把blogs上的解决方法给copy过来了,这是原文链接地址 http://seaboycs.iteye.com/blog/2015230
希望能够帮助遇到同样问题的朋友,也给自己的工作总结一下
今天遇到一个Datatables常见的问题,搞了好久没弄好,查看baidu也没有成果,在google上查到了原因。
问题:
DataTables warning: Requested unknown parameter '3' from the data source for row 0
JS:
- function initializeEvents() {
- $('.datatable').dataTable({
- "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
- "bServerSide" : true,
- "sAjaxSource" : "/uploadDemo/admin/photo/list.spring",
- "sServerMethod" : "POST" ,
- "bProcessing" : false,
- "bPaginate": true,
- "bLengthChange" : true,
- "iDisplayLength" : 10,
- "fnAdjustColumnSizing" : false,
- "bStateSave": false,
- "bSort":false,
- "bFilter":false,
- "aoColumnDefs" : makeCollumnDef(),
- "aoColumns" : makeCollomns(),
- "sPaginationType": "bootstrap",
- "oLanguage": {
- "sLengthMenu": "_MENU_ records per page"
- }
- } );
- }
- function makeCollumnDef() {
- return [
- { "fnRender" : function (oObj, sVal) {
- return oObj.aData.id;
- },
- "bVisible" : true ,
- "aTargets" : [ 0 ]
- },
- { "fnRender" : function (oObj, sVal) {
- return oObj.aData.name;
- },
- "bVisible" : true ,
- "aTargets" : [ 1 ]
- },
- { "fnRender" : function (oObj, sVal) {
- return "<img src='/uploadDemo/" +oObj.aData.path +"' width=50px height=40px />";
- },
- "bVisible" : true ,
- "aTargets" : [ 2 ]
- },
- { "fnRender" : function (oObj, sVal) {
- return createAction(oObj.aData.id);
- },
- "bVisible" : true ,
- "aTargets" : [ 3 ]
- }];
- }
- function makeCollomns(){
- return [{ "mDataProp" : "id", "sHeight":"15px"},
- { "mDataProp" : "name"},
- { "mDataProp" : "path"}}];
- }
- function createAction(id) {
- var inhtml = '<a class="btn btn-success" href="/uploadDemo/admin/photo/view.spring?id=' + id + '">';
- inhtml += '<i class="icon-zoom-in icon-white"></i>View</a> ';
- inhtml += '<a class="btn btn-info" href="/uploadDemo/admin/photo/preUpdate.spring?id=' + id + '">';
- inhtml += '<i class="icon-edit icon-white"></i>Edit</a> ';
- inhtml += '<a class="btn btn-danger" href="/uploadDemo/admin/photo/delete.spring?id=' + id + '">';
- inhtml += '<i class="icon-trash icon-white"></i>Delete</a>';
- return inhtml;
- }
参考了 https://gist.github.com/kagemusha/1660712 这个大神的解决方案:
意思就是 aoColumns 和 aoColumnDefs的个数必须相等,否则会出错,由于我在表格中加入了一个Action列,导致aoColumns 和 aoColumnDefs的数目不等,就出了上面的错,该法就比较简单:
在 Java Bean 中添加一个任意字段,把他添加到aoColumnDefs 就好了。
- public class PhotoBean {
- private int id;
- private String name;
- private String path;
- private String checked;
- function makeCollomns(){
- return [{ "mDataProp" : "id", "sHeight":"15px"},
- { "mDataProp" : "name"},
- { "mDataProp" : "path"},
- { "mDataProp" : "checked"}];
我添加了一个checked的字符串,问题解决。
Jquery DataTables warning : Requested unknown from the data source for row 0的更多相关文章
- DataTables warning : Requested unknown parameter '5' from the data source for row 0
在该项目中我使用了jquery.dataTables.js来作为我的前端数据表格. 表格的官网地址:https://www.datatables.net/ 一.jsp部分代码片段如下: <tab ...
- DataTables warning : Requested unknown parameter '0' from the data source for row 0错误
在做datatables的项目,从后台取得数据后,返回给datatables界面时会报下面的错误: DataTables warning : Requested unknown parameter ' ...
- DataTables warning: table id=dataTable - Requested unknown parameter 'acceptId' for row 0. For more
重点内容 DataTables warning: table id=dataTable - Requested unknown parameter 'acceptId' for row 0. For ...
- DataTables warning requested unknown parameter
This is possibly the most cryptic warning message that DataTables will show. It is a short error mes ...
- DataTables warning (table id = 'myTable'): Requested unknown parameter '0' from the data source for row 0
第一种方式:不用在js里设置列Html: <table id="myTable"> <thead> <tr> <th>Title-1 ...
- data source 和initial catalog
initial catalog与database的区别是什么Initial Catalog: DataBase: 两者没有任何区别只是名称不一样,就好像是人类的真实姓名与曾用名一样..都可以叫你. * ...
- DataTables warning: table id=data-table - Requested unknown parameter '3' for row 0.
本文为博主原创,未经允许,不得转载: 在使用jquery 的datatable时,报错在页面弹出弹出框,并提示以下内容: DataTables warning: table id=data-table ...
- jquery dataTables.min.js API
demo: http://datatables.net/release-datatables/examples/api/select_single_row.html 选择一行http://datata ...
- jquery datatables api (转)
学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...
随机推荐
- HTML/CSS的学习过程一览
HTML/CSS的学习过程一览 说明 调试工具使用的是Google Chrome浏览器,其余浏览器出现的问题,这锅我不背[傲娇脸 可以使用浏览器查看源代码 网页列表 HTML_CSS_1 HTML基本 ...
- 多线程 -- NSOperation
NSOperation 此类不能直接使用 NSInvocationOperation NSBlockOperation 定义一个类继承与它 NSInvocationOperation 可以使用star ...
- ListView单击单元格 产生其他控件
以combobox为例. 假如一行里面只有一个combobox. //在类中声明一个控件数组 private ComboBox[] cmds = null; //initview中调用dao组件获得显 ...
- MVC 数据验证收集代码
控制器 Home using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- android 下载图片出现SkImageDecoder::Factory returned null,BitmapFactory.Options压缩
网上有很多说是因为没有采用HttpClient造成的,尼玛,我改成了HttpClient 请求图片之后还是会出现SkImageDecoder::Factory returned null, 但是直接使 ...
- [转载]char * 和char []的区别---之第一篇
char * 和char []的区别---之第一篇 原文地址http://blog.csdn.net/yahohi/article/details/7427724 在C/C++中,指针和数组在很多地 ...
- JS 学习笔记--JS中的事件对象基础
事件:JavaScript中的事件是由访问web页面用户的一系列操作引起的,比如点击鼠标,键盘按键等.当用户执行某些操作的时候再去执行一些代码. 事件模型:内联模型.脚本模型.DOM2模型 内联模型: ...
- ios UI实现技巧
statusBar 移动位置 NSString *key = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned ] enco ...
- redis提示Could not get a resource from the pool(jedis连接池配置)
起初在JedisPool中配置了50个活动连接,但是程序还是经常报错:Could not get a resource from the pool 连接池刚开始是这样配置的: JedisPoolCon ...
- python抓取汇率
# -*- coding: utf-8 -*- """ 获取实时汇率 Created on Fri Oct 18 13:11:40 2013 @author: alala ...