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
- 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": Ten,
- "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;
- }
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
- Public class Photobean {
- private int id;
- private String name;
- private String path;
- private String checked;
JS Code
- function Makecollomns () {
- return [{ "Mdataprop": "id", "sheight":"15px"},
- { "Mdataprop": "Name"},
- { "Mdataprop": "Path"},
- { "Mdataprop": "checked"}];
I added a checked string to solve the problem.