3 Answers, 1 is accepted
0

Millcom
Top achievements
Rank 1
answered on 24 Aug 2012, 04:04 PM
i got the solution
<div id="grid"></div>
<script>
$(document).ready(function () {
isEditing = false;
isCreating = false;
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 30,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } },
},
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 400,
toolbar: [{name:"create",text:"Agregar Producto"}],
columns: [
{ field:"ProductName", title: "Product Name" },
{ field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "150px" },
{ field: "UnitsInStock", title:"Units In Stock", width: "150px" },
{ field: "Discontinued", width: "100px" },
{ command: [{name:"edit",text:"Editar"}, {name:"destroy",text:"Eliminar"}], title: " ", width: "210px" }],
editable: {mode:"popup"},
edit:function(e){
if(isEditing){
e.container.kendoWindow("title","Modify");
}else if(isCreating){
e.container.kendoWindow("title","Create");
}
}
});
$(".k-grid-edit").on("click",function(){
isEditing = true;
});
$(".k-grid-add").on("click",function(){
console.log("xad");
isCreating = true;
});
});
<script>
$(document).ready(function () {
isEditing = false;
isCreating = false;
var crudServiceBaseUrl = "http://demos.kendoui.com/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 30,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } },
},
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 400,
toolbar: [{name:"create",text:"Agregar Producto"}],
columns: [
{ field:"ProductName", title: "Product Name" },
{ field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "150px" },
{ field: "UnitsInStock", title:"Units In Stock", width: "150px" },
{ field: "Discontinued", width: "100px" },
{ command: [{name:"edit",text:"Editar"}, {name:"destroy",text:"Eliminar"}], title: " ", width: "210px" }],
editable: {mode:"popup"},
edit:function(e){
if(isEditing){
e.container.kendoWindow("title","Modify");
}else if(isCreating){
e.container.kendoWindow("title","Create");
}
}
});
$(".k-grid-edit").on("click",function(){
isEditing = true;
});
$(".k-grid-add").on("click",function(){
console.log("xad");
isCreating = true;
});
});
0

Joseph
Top achievements
Rank 1
answered on 20 Apr 2017, 06:52 PM
If the record you are creating/editing has an Id you can do this in the edit function:
if
(!e.model.Id) {
e.container.kendoWindow(
"title"
,
"Create"
);
}
else
{
e.container.kendoWindow(
"title"
,
"Modify"
);
}
0

Joseph
Top achievements
Rank 1
answered on 20 Apr 2017, 07:33 PM
Or better you can do this:
if
(e.model.isNew()){
}
else
{
}