grid save new item not dirty
by grippstick
HTML
<link rel="stylesheet" href="https://aligntoday.com/Kendo/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://aligntoday.com/Kendo/styles/kendo.flat.min.css">
<script src="https://aligntoday.com/Kendo/js/jquery.min.js"></script>
<script src="https://aligntoday.com/Kendo/js/kendo.all.min.js"></script>
<div id='container'>
<div class="padding addListItem">
<input class="radoloInput" data-role='inputplaceholder' placeholder='Category' data-bind='value:newItem.Category' />
<input class="radoloInput" data-role='inputplaceholder' placeholder='Field Label' data-bind='value:newItem.FieldLabel' />
<select data-role='dropdownlist' data-bind='value:newItem.DataType' data-value-primitive='true'>
<option value='Number'>Number</option>
<option value='Decimal'>Decimal</option>
<option value='TextShort'>Short Text</option>
<option value='TextLong'>Long Text</option>
<option value='Date'>Date</option>
<option value='DateTime'>Date & Time</option>
<option value='Yes/No'>Yes/No</option>
</select>
<button class="button green circle" data-bind='click:clickAddItem'>Add</button>
</div>
<div data-height="200px" data-role='grid' data-bind='source:dsItems,events:{save:saveGridItem}' data-editable='incell' data-auto-bind='false' data-scrollable='true' data-sortable='false' data-pageable='false' data-columns='[{field:"Category",title:"Category"},{field:"FieldLabel",title:"Field Label"},{field:"DataType",title:"Data Type",values: [{value:"Number", text:"Number"},{value:"Decimal", text:"Decimal"},{value:"TextShort", text:"Short Text"},{value:"TextLong", text:"Long Text"},{value:"Date", text:"Date"},{value:"DateTime", text:"Date & Time"},{value:"Yes/No", text:"Yes/No"}]}]'></div>
</div>
JavaScript
var $container = $('#container');
var vm = new kendo.observable({
newItem: {
Category: '',
FieldLabel: '',
DataType: 'TextShort',
FieldValue:''
},
clickAddItem: function (e) {
e.preventDefault();
//if it has an id then it will not trigger create
var item = vm.get('newItem');
vm.dsItems.add(item);
vm.dsItems.sync();
},
dsItems: new kendo.data.DataSource({
transport: {
read: {
cache: false,
async: true,
type: "GET",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
url: "http://babackofficedev.radolo.com/services/PublicAPI.svc/ReadItems" },
update: {
cache: false,
async: true,
type: "GET",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
url: "http://babackofficedev.radolo.com/services/PublicAPI.svc/SaveItem"
},
create: {
cache: false,
async: true,
type: "GET",
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
url: "http://babackofficedev.radolo.com/services/PublicAPI.svc/SaveItem"
},
parameterMap: function (options, action) {
console.warn(action);
if (action === 'read') {
return options;
}
if (action === 'create') {
delete options.__type;
delete options.dirty;
options.ID=-1;
//we want all roles all the time
return {
Field: kendo.stringify(options)
};
}
if (action === 'update') {
...