Jquery DataTables warning:requested Unknown from the data source for row 0

Source: Internet
Author: User

When I was doing Jquery DataTables yesterday, I encountered a problem that I used MVC and added a actionlink href to tables. But in the run up, the error:

DataTables warning:requested Unknown parameter ' 3 ' from the data source for row 0

By searching the online big God solution, so I put blogs on the solution to copy, this is the original link address http://seaboycs.iteye.com/blog/2015230

Hope to help meet the same problems of friends, but also for their work to summarize

Today encountered a DataTables common problems, engaged for a long time did not fix, check Baidu also no results, on Google found the reason.

Problem:

DataTables warning:requested Unknown parameter ' 3 ' from the data source for row 0

Js:

JS Code
  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": Ten,
  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. }

Refer to the solution of https://gist.github.com/kagemusha/1660712, the Great god:

Meaning that the number of aocolumns and aocolumndefs must be equal, otherwise it will be wrong, because I added an Action column in the table, resulting in aocolumns and aocolumndefs the number of unequal, the above error, the method is relatively simple:

Add an arbitrary field to the Java Bean and add it to the aocolumndefs.

Java code
    1. Public class Photobean {
    2. private int id;
    3. private String name;
    4. private String path;
    5. private String checked;

JS Code
    1. function Makecollomns () {
    2. return [{ "Mdataprop": "id", "sheight":"15px"},
    3. { "Mdataprop": "Name"},
    4. { "Mdataprop": "Path"},
    5. { "Mdataprop": "checked"}];

I added a checked string to solve the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.