JSGrid Insert Reject
HTML
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/redmond/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.1/jsgrid.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.1/jsgrid.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.1/jsgrid-theme.css">
<div id="jsGrid"></div>
CSS
.jsgrid-cell {
overflow: hidden;
}
.jsgrid-pager { text-align: center; }
JavaScript
var dataaux;
var obj2=[];
var data = [
{
"Name": "Test Test",
"Married": false,
"id_sup":0
},
{
"Name": "Connor Johnston",
"Married": false,
"id_sup":1
},
{
"Name": "Lacey Hess",
"Married": false,
"id_sup":0
},
{
"Name": "Timothy Henson",
"Married": false,
"id_sup":1
}
];
//obj2='[';
var text='{"data":'+JSON.stringify(data)+'}'
for(var i=0;i<4;i++)
{
obj=JSON.parse(text)
if(obj.data[i].id_sup==0)
{
obj.data[i].id_sup=1;
// alert( '{ "name":"John", "age":30, "city":"New York"}')
var f=JSON.parse('{"Name"'+':'+'"'+obj.data[i].Name+'", '+'"Married"'+':'+obj.data[i].Married+', '+'"id_sup"'+':'+obj.data[i].id_sup+'}')
obj2[i]=f;
console.log(obj2);
}
else
{
obj.data[i].id_sup=0;
var f=JSON.parse('{"Name"'+':'+'"'+obj.data[i].Name+'", '+'"Married"'+':'+obj.data[i].Married+', '+'"id_sup"'+':'+obj.data[i].id_sup+'}')
obj2[i]=f;
}
}
console.log(data);
$("#jsGrid").jsGrid({
height: 300,
width: "100%",
autoload: true,
inserting: true,
controller: {
loadData: function() {
return obj2;
},
},
fields: [
{ name: "Name", title:"Name", type: "text", width: "60%", validate: "required" },
{ name: "Married", title:"Married", type: "checkbox", width: "30%", validate: "required" },
{name:"id_sup",title:"Supervisor", type:"checkbox",width:"30%",validate:"required"
},
{
type: "control", width: "10%",
headerTemplate: function()
{
...