javascript - Kendo UI Angular Upload / Kendo Grid integration -


ok, here versions:

  • kendo ui v2014.3.1119
  • angularjs v1.3.6
  • jquery v@1.8.1 jquery.com

the issue following: have kendo upload should populate grid after excel file read. i'm using kendo ui angular directives. here key pieces of code:

upload html

 <input name="files"                type="file"                kendo-upload                k-async="{ saveurl: '{{dialogoptions.importurl}}', autoupload: false, batch: true }"                k-options="{localization: {uploadselectedfiles: '{{messages.global_button_import}}'}}"                k-error="onimporterror"                k-select="onselect"                k-success="onimportsuccess" k-multiple="false" /> 

grid html

 <div kendo-grid="grid" k-options="gridoptions" k-ng-delay="gridoptions" k-rebind="gridoptions" >         </div> 

key pieces on controller

angular.module('global').controller('importresultscontroller', [ '$scope', 'baseapi', 'importresultsservice', 'gridutil', '$http', '$q', '$timeout', function ($scope, baseapi, importresultsservice, gridutil, $http, $q, $timeout) {   $scope.gridoptions;     $scope.gridcolumns;     $scope.results = new kendo.data.observablearray([]);  //these columns should come server, right harcoded  $scope.getgridcolumns = function () {         $scope.gridcolumns = [                { field: "zone", width: 70, title: "zone", template: "" },                { field: "aisle", width: 70, title: "aisle", template: "" },                { field: "rack", width: 70, title: "rack", template: "" },                { field: "shelf", width: 70, title: "shelf", template: "" },                { field: "bin", width: 70, title: "bin", template: "" },                //{ field: "dateeffectivefrom", width: 70, title: "date" },                { field: "binstatus", width: 70, title: "binstatus", template: "" }         ];     }   $scope.getclientgridoptions = function(columns,  data, pagesize) {      var gridoptions = {         sortable: true,         datasource: {             data: data,             pagesize: pagesize         },         selectable: 'row',         columns: columns,         pageable: {             pagesize: pagesize,             refresh: false,                             pagesizes: [10, 20, 30],             messages: $.kendomessages         },     };      return gridoptions }  $scope.onimportsuccess = function (e) {         var files = e.files;          if (e.operation == "upload") {             console.log(files);             if (e.xmlhttprequest.response != "") {                 var model = $.parsejson(e.xmlhttprequest.response); //this step not fail, model return filled                 $scope.results = new kendo.data.observablearray([]);                  (var = 0; < model.data.length; i++) {                     $scope.results.push(model.data[i]);                 }                  $scope.gridoptions = $scope.getclientgridoptions($scope.gridcolumns, $scope.results, 10);                 //$scope.grid.datasource.data($scope.results); //this not work                  $scope.isdataready = true;                 // $("#grid").data("kendogrid").datasource.data($scope.results) //this not work                                  // $scope.grid.refresh(); //this not work                 $scope.$apply()                }                         }                        }  }]); 

the issues vary. data bound until second uploaded file, , after third time, start receiving 'cannot read property 'get' of undefined ' errors. when second error happens, bind works, error present. have idea of be?

in case of need url upload, here's method. mvc .net application. since response correctly , it's json array, believe there's no issue there, here's anyways.

dialogoptions.importurl = loadimportedbinlocations 

mvc controller

[system.web.http.httppost]     public actionresult loadimportedbinlocations(ienumerable<httppostedfilebase> files)     {         bool success = false;          var importhistory = new partsimporthistory();         list<dynamic> data = null;         try         {             //int divisor = 0;             //var y = 5 / divisor;              if (files != null)             {                 using (var client = new servicelocator<ipartsservice>())                 {                     foreach (var file in files)                     {                         string extension = path.getextension(file.filename);                         bool isexcelfile = extension == ".xls" || extension == ".xlsx";                          if (isexcelfile)                         {                             var filepath = uploadattachment(file);                              //importhistory = client.service.savepartsimporthistory(new partsimporthistory                             //{                             //    createdbyname = currentcontext.userdisplayname,                             //    createdbyuserid = currentcontext.userid,                             //    partsimportstatus = (int)dmsmodel.enumstore.partsimportstatus.inprogress,                             //    filepath = filepath                             //});                             data = new list<dynamic>                                  {                                      new { zone = "a", aisle = "02", rack = "06", shelf = "20", bin = "d", dateeffectivefrom = datetime.utcnow, binstatus = "unblocked", isvalid= true, importerror ="" },                                     new { zone = "b", aisle = "02", rack = "06", shelf = "10", bin = "d", dateeffectivefrom = datetime.utcnow, binstatus = "blocked", isvalid=false, importerror="zone not exist" }                                 };                              success = true;                         }                         else                         {                             throw new exception(warpdms.globalization.resources.partsadmin_importparts_errorfileformat);                         }                     }                 }             }              return json(new { success = success, data = data });         }         catch (exception ex)         {             return content(ex.message ?? ex.tostring());         }     }      private string uploadattachment(httppostedfilebase item)     {         string path = string.empty;         string internalfilename = string.empty;         string basepath = configmanager.attachments_path;          if (item != null && item.contentlength > 0)         {             internalfilename = system.io.path.changeextension(guid.newguid().tostring(), system.io.path.getextension(item.filename));             path = path.combine(basepath, internalfilename);              item.saveas(path);         }          return path.combine(basepath, internalfilename).replace('\\', '/');     } 


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -