2

i tried to use kendo grid by crud Operation that cooperate with Jaydata and angularjs to create DataSource and implement crud Operation.but when i update or create a record after submit on server i have an error in kendo.js of jayadataModules.because the save funcion of entity in angular(in jaydataModules)return promise object that contains catch,finaly,then function and doen't have fail function.

here is my jaydata context:

(function(global, $data, undefined) {
        $data.Entity.extend('ComplexEntity', {
              'Name': { 'type': 'Edm.String' },
              'Created': { 'type': 'Edm.DateTime', 'nullable': false, 'required': false },
              'Index': {'key':true,'computed': true, 'type': 'Edm.Int32', 'nullable': false, 'required': true },
              'LargeNum': { 'type': 'Edm.Int64', 'nullable': false, 'required': true }
          });

         $data.generatedContexts = $data.generatedContexts || [];
         $data.generatedContexts.push(TestContext.Container);

    })(window, $data);

app.js:

var app = angular.module('app', ['jaydata']);

DataSource.js:

app.factory('dataSource', ['$data', function ( $data) {

    return {
        get: function (serviceUri) {
            debugger;
            var context = new $data.initService(serviceUri);
            return context;
        }
    };
}]);

grid-directive.js:

app.directive('crudGrid', function () {

    return {
        restrict: 'A',
        scope:{
            ds:'=',
        },

        controller: function ($scope,$element,$attrs, $data, dataSource) {

            serviceUri = '/odata';
            var tag = $element;
            var context = dataSource.get(serviceUri);
            context.then(function (db) {

                ds = db.ComplexEntity.asKendoDataSource();
                kendo.init($("#" + tag[0].id));

            }).fail(function (args) {
               //some code here 
            });
        }
    }
});

ComplexEntityController:

public class ComplexEntityController :ODataController
    {
      [Queryable]
        public IQueryable<ComplexEntity> Get(ODataQueryOptions<ComplexEntity> options)
        {
            return complexList.AsQueryable();
        }

         public HttpResponseMessage Post(ComplexEntity entity)
        {
            if (ModelState.IsValid)
            {
                // some code here 

                return Request.CreateResponse<ComplexEntity>(entity);
            }

            else
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
        }

         public ComplexEntity Patch(int key, Delta<ComplexEntity> patch)
        {
            var entity = complexList.First(t => t.Index == key);

            patch.Patch(entity);

            return entity;

        }
  }

Index.cshtml:

<link href="~/Content/kendo/2013.1.514/kendo.common.min.css" rel="stylesheet" /> 
<link href="~/Content/kendo/2013.1.514/kendo.default.min.css" rel="stylesheet" /> 
<link href="~/Content/kendo/2013.1.514/kendo.rtl.min.css" rel="stylesheet" />

<script src="~/Scripts/angular-1.2.0-rc.2/angular.js"></script>
<script src="~/Scripts/datajs-1.0.3.min.js"></script> <script src="~/Scripts/jaydata-1.3.6/jaydata.js"></script> 
<script src="~/Scripts/jaydata-1.3.6/jaydatamodules/deferred.js"></script> 
<script src="~/Scripts/jaydata-1.3.6/jaydatamodules/angular.js"></script> 
<script src="~/Scripts/kendo/2013.1.514/kendo.all.min.js"></script> 
<script src="~/Scripts/kendo/2013.1.514/kendo.web.min.js"></script> 
<script src="~/Scripts/kendo/2013.1.514/kendo.aspnetmvc.min.js"></script> <script src="~/Scripts/jaydata-1.3.6/jaydatamodules/kendo.js"></script> 
<script src="~/Scripts/ViewModels.js"></script> <script src="~/Scripts/App/app.js"></script> <script src="~/Scripts/App/Services/DataSource.js"></script> 
<script src="~/Scripts/App/Controller/FillGrid.js"></script> 
<script src="~/Scripts/App/Directives/grid-directive.js"></script>



<div class="k-rtl" style="margin-right:10px; width:1000px;float:right;">

    <div id="mvvmGrid" crud-grid data-role="grid"
         data-selectable="true" data-height="450"
         data-sortable="true"
         data-editable="inline"
         data-filterable="true"
         data-toolbar='["create", "save", "cancel"]'
         data-columns='[
                                        { field: "Name",  width: "180px" },
                                        { field: "Created", width: "200px" },
                                        { field: "LargeNum", width: "180px" },
                                        { field: "Index",hidden:true },
                                        { command :["edit", "destroy", "update"]}
                                      ]'
         data-pageable="{ refresh: true, pageSizes: true }"
         data-source="ds" />
    </div>
</div>

when i update record i have an error:'undefined is not a function' on kendo.js at this line :

 model[0].innerInstance().save().then(function (item) {
                                options.success();
                            }).fail(function () {

                                options.error({}, arguments);

                            });

because the save function has no fail function . Where is my mistake?

maryam
  • 31
  • 3

0 Answers0