昨天在做 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:

  1. function initializeEvents() {
  2. $('.datatable').dataTable({
  3. "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
  4. "bServerSide" : true,
  5. "sAjaxSource" : "/uploadDemo/admin/photo/list.spring",
  6. "sServerMethod" : "POST" ,
  7. "bProcessing" : false,
  8. "bPaginate": true,
  9. "bLengthChange" : true,
  10. "iDisplayLength" : 10,
  11. "fnAdjustColumnSizing" : false,
  12. "bStateSave": false,
  13. "bSort":false,
  14. "bFilter":false,
  15. "aoColumnDefs" : makeCollumnDef(),
  16. "aoColumns" : makeCollomns(),
  17. "sPaginationType": "bootstrap",
  18. "oLanguage": {
  19. "sLengthMenu": "_MENU_ records per page"
  20. }
  21. } );
  22. }
  23. function makeCollumnDef() {
  24. return [
  25. { "fnRender" : function (oObj, sVal) {
  26. return oObj.aData.id;
  27. },
  28. "bVisible" : true ,
  29. "aTargets" : [ 0 ]
  30. },
  31. { "fnRender" : function (oObj, sVal) {
  32. return oObj.aData.name;
  33. },
  34. "bVisible" : true ,
  35. "aTargets" : [ 1 ]
  36. },
  37. { "fnRender" : function (oObj, sVal) {
  38. return "<img src='/uploadDemo/" +oObj.aData.path +"' width=50px height=40px />";
  39. },
  40. "bVisible" : true ,
  41. "aTargets" : [ 2 ]
  42. },
  43. { "fnRender" : function (oObj, sVal) {
  44. return createAction(oObj.aData.id);
  45. },
  46. "bVisible" : true ,
  47. "aTargets" : [ 3 ]
  48. }];
  49. }
  50. function makeCollomns(){
  51. return [{ "mDataProp" : "id", "sHeight":"15px"},
  52. { "mDataProp" : "name"},
  53. { "mDataProp" : "path"}}];
  54. }
  55. function createAction(id) {
  56. var inhtml = '<a class="btn btn-success" href="/uploadDemo/admin/photo/view.spring?id=' + id + '">';
  57. inhtml += '<i class="icon-zoom-in icon-white"></i>View</a> ';
  58. inhtml += '<a class="btn btn-info" href="/uploadDemo/admin/photo/preUpdate.spring?id=' + id + '">';
  59. inhtml += '<i class="icon-edit icon-white"></i>Edit</a> ';
  60. inhtml += '<a class="btn btn-danger" href="/uploadDemo/admin/photo/delete.spring?id=' + id + '">';
  61. inhtml += '<i class="icon-trash icon-white"></i>Delete</a>';
  62. return inhtml;
  63. }

参考了 https://gist.github.com/kagemusha/1660712 这个大神的解决方案:

意思就是 aoColumns 和 aoColumnDefs的个数必须相等,否则会出错,由于我在表格中加入了一个Action列,导致aoColumns 和 aoColumnDefs的数目不等,就出了上面的错,该法就比较简单:

在 Java Bean 中添加一个任意字段,把他添加到aoColumnDefs 就好了。

  1. public class PhotoBean {
  2. private int id;
  3. private String name;
  4. private String path;
  5. private String checked;
  1. function makeCollomns(){
  2. return [{ "mDataProp" : "id", "sHeight":"15px"},
  3. { "mDataProp" : "name"},
  4. { "mDataProp" : "path"},
  5. { "mDataProp" : "checked"}];

我添加了一个checked的字符串,问题解决。

Jquery DataTables warning : Requested unknown from the data source for row 0的更多相关文章

  1. DataTables warning : Requested unknown parameter '5' from the data source for row 0

    在该项目中我使用了jquery.dataTables.js来作为我的前端数据表格. 表格的官网地址:https://www.datatables.net/ 一.jsp部分代码片段如下: <tab ...

  2. DataTables warning : Requested unknown parameter '0' from the data source for row 0错误

    在做datatables的项目,从后台取得数据后,返回给datatables界面时会报下面的错误: DataTables warning : Requested unknown parameter ' ...

  3. DataTables warning: table id=dataTable - Requested unknown parameter &#39;acceptId&#39; for row 0. For more

    重点内容 DataTables warning: table id=dataTable - Requested unknown parameter 'acceptId' for row 0. For ...

  4. DataTables warning requested unknown parameter

    This is possibly the most cryptic warning message that DataTables will show. It is a short error mes ...

  5. 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 ...

  6. data source 和initial catalog

    initial catalog与database的区别是什么Initial Catalog: DataBase: 两者没有任何区别只是名称不一样,就好像是人类的真实姓名与曾用名一样..都可以叫你. * ...

  7. DataTables warning: table id=data-table - Requested unknown parameter '3' for row 0.

    本文为博主原创,未经允许,不得转载: 在使用jquery 的datatable时,报错在页面弹出弹出框,并提示以下内容: DataTables warning: table id=data-table ...

  8. jquery dataTables.min.js API

    demo: http://datatables.net/release-datatables/examples/api/select_single_row.html 选择一行http://datata ...

  9. jquery datatables api (转)

    学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...

随机推荐

  1. HTML/CSS的学习过程一览

    HTML/CSS的学习过程一览 说明 调试工具使用的是Google Chrome浏览器,其余浏览器出现的问题,这锅我不背[傲娇脸 可以使用浏览器查看源代码 网页列表 HTML_CSS_1 HTML基本 ...

  2. 多线程 -- NSOperation

    NSOperation 此类不能直接使用 NSInvocationOperation NSBlockOperation 定义一个类继承与它 NSInvocationOperation 可以使用star ...

  3. ListView单击单元格 产生其他控件

    以combobox为例. 假如一行里面只有一个combobox. //在类中声明一个控件数组 private ComboBox[] cmds = null; //initview中调用dao组件获得显 ...

  4. MVC 数据验证收集代码

    控制器 Home using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...

  5. android 下载图片出现SkImageDecoder::Factory returned null,BitmapFactory.Options压缩

    网上有很多说是因为没有采用HttpClient造成的,尼玛,我改成了HttpClient 请求图片之后还是会出现SkImageDecoder::Factory returned null, 但是直接使 ...

  6. [转载]char * 和char []的区别---之第一篇

    char *  和char []的区别---之第一篇 原文地址http://blog.csdn.net/yahohi/article/details/7427724 在C/C++中,指针和数组在很多地 ...

  7. JS 学习笔记--JS中的事件对象基础

    事件:JavaScript中的事件是由访问web页面用户的一系列操作引起的,比如点击鼠标,键盘按键等.当用户执行某些操作的时候再去执行一些代码. 事件模型:内联模型.脚本模型.DOM2模型 内联模型: ...

  8. ios UI实现技巧

    statusBar 移动位置 NSString *key = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned ] enco ...

  9. redis提示Could not get a resource from the pool(jedis连接池配置)

    起初在JedisPool中配置了50个活动连接,但是程序还是经常报错:Could not get a resource from the pool 连接池刚开始是这样配置的: JedisPoolCon ...

  10. python抓取汇率

    # -*- coding: utf-8 -*- """ 获取实时汇率 Created on Fri Oct 18 13:11:40 2013 @author: alala ...