Hi,
Am new to .Net web application, datatables and editor. I went through the basic examples in the website. I am facing an issue. Hope someone can throw some light on this.
Please find below the code that i use and error message i get.
HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xxx.cs" Inherits="xxx" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- end required meta tags -->
<title>test</title>
<link href="../DataTables/Bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet" type="text/css" /><!-- Do not edit -->
<link href="../DataTables/Bootstrap-3.3.7/css/bootstrap-theme.css" rel="stylesheet" type="text/css" /><!-- Define theme changes here. -->
<link href="../DataTables/DataTables-1.10.13/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../DataTables/Buttons-1.2.4/css/buttons.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../DataTables/Select-1.2.0/css/select.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../DataTables/Editor-1.6.1/css/editor.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../Styles/test.css" rel="stylesheet" type="text/css" />
<script src="../DataTables/datatables.min.js" type="text/javascript"></script>
<script src="../Scripts/test.js" type="text/javascript"></script>
<!-- End JavaScript Includes -->
</head>
<body>
</body>
</html>
Javascript:
(function () {
var editor;
$(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: {
url: "URL to DB service",
contentType: "application/json; charset=utf-8",
dataType: "json" },
table: "#Grid-01",
fields: [
{
"label": "col 1",
"name": "col1"
},
{
"label": "col 2",
"name": "col2"
},
{
"label": "col 3",
"name": "col3"
},
{
"label": "col 4",
"name": "col4"
},
{
"label": "col 5",
"name": "col5"
}
],
formOptions: {
inline: {
onBlur: 'submit' }
}
});
var table = $('#Grid-01').DataTable({
lengthChange: false,
order: [],
ajax: {
url: "URL to DB service",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "GET",
dataSrc: "d"
},
columns: [
{ "data": "col1" },
{ "data": " col2" },
{ "data": " col3" },
{ "data": " col4" },
{ "data": " col5" }
]
});
// Display the buttons
new $.fn.dataTable.Buttons(table, [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]);
//Add the buttons to the appropriate Bootstrap class
table.buttons().container()
.appendTo($('.col-sm-6:eq(0)', table.table().container()));
$('#Grid-01').on('click', 'tbody td:not(:first-child)', function (e) {
editor.inline(this);
});
});
} ());
Output of DB service:
{"d":"[{\"col1\":\"12345\",\"col2\":\"123\",\"col3\":\"123\",\"col4\":\"100\",\"col5\":\"test_1]"}
Error message :
Datables warning: table id = Grid-01 – Requested unknown parameter ‘col1’ for row 0, column 0.
Thanks!