asp.net mvc - Bind results from search -


i cannot bind results search in kendo grid. i've tried many times, i'm in trouble 4 days, don't know wrong here,

when debug action working perfect,data ok, return grid result ok, results aren't shown in kendo.

here code:

<script>    $(function() {      $("a.k-button").on('click', function (e) {        debugger;       e.preventdefault();        var dataobj = serializebyfieldswrap(".invoiceform");       var dataurl = $(this).data('url');        // dataobj.toolboxid = toolboxid;        $('body').css('cursor', 'wait');        var result = $.ajax({         type: "post",         url: dataurl,         datatype: 'json',         data: dataobj,         //complete:  $("#invoices-grid").data("kendogrid").data.read(),        });        result.done(function (data) {         console.log(data);          var grid = $('#invoices-grid').data("kendogrid");         grid.datasource.data(data);       });        result.fail(function (error) {         console.log(error);       });      });    });  </script> 

controller:

public actionresult list(datasourcerequest command, financelistmodel model) {   var searchstring = model.searchjobitemnumber;   var ischecked = model.ischecked;   var invoices = _invoiceservice.getallinvoices(searchstring, ischecked);    var gridmodel = new datasourceresult   {     data = invoices.select(x => {       var jobmodel = x.tomodel();       return jobmodel;     }),     total = invoices.totalcount   };    return json(gridmodel, "application/json", jsonrequestbehavior.allowget); } 

kendo ui grid:

<script>    $(function() {     $("#invoices-grid").kendogrid({        datasource: {         data: @html.raw(jsonconvert.serializeobject(model.invoices)),         schema: {           model: {             fields: {               jobnumber: { type: "string" },               customername: { type: "string" },               departmentname: { type: "string" },               dateinvoice: { type: "string" },               validdays: { type: "number" },               delivery: { type: "string" },               ispayed: { type: "boolean" },               payed: { type: "number" },               status: { type: "boolean" },             },             error: function(e) {               display_kendoui_grid_error(e);               // cancel changes               this.cancelchanges();             },             pagesize: 20,             serverpaging: true,             serverfiltering: true,             serversorting: true           },           databound: function () {             var row = this.element.find('tbody tr:first');             this.select(row);           },            columns: [             @*{               field: "status",               title: "@t("gp.jobs.fields.status")",               template: '#= status #'             },*@              {                field: "jobnumber",                title: "@t("gp.invoice.fields.jobnumber")",                template: '#= jobnumber #'              },              {                field: "customername",                title: "@t("gp.invoice.fields.customername")",                template: '#= customername #'              },              {                field: "departmentname",                title: "@t("gp.invoice.fields.departmentname")",                template: '#= departmentname #'              },              {                field: "dateinvoice",                title: "@t("gp.invoice.fields.dateinvoice")",                template: '#= dateinvoice #'              },              {                field: "validdays",                title: "@t("gp.invoice.fields.validdays")",                template: '#= validdays #'              },              {                field: "delivery",                title: "@t("gp.invoice.fields.delivery")",                template: '#= delivery #'              },              {                field: "payed",                title: "@t("gp.invoice.fields.ispayed")",                template: '#= (payed == 2) ? "Комп." : ((payed == 1) ? "ДЕ" : "НЕ") #'              },              {                field: "id",                title: "@t("common.edit")",                width: 100,                template: '<a href="edit/#=id#">@t("common.edit")</a>'              }             ],             pageable: {             refresh: true,             pagesizes: [5, 10, 20, 50]         },         editable: {           confirmation: false,           mode: "popup"         },         scrollable: false,          selectable: true,         change: function(e) {           var selectedrows = this.select();            var jobid = parseint($(selectedrows).data('job-id'));           var jobitemid = parseint($(selectedrows).data('job-item-id'));            var result = $.get("@url.action("sidedetails", "production")/" + jobitemid);            result.done(function(data) {              if (data) {               $(".job-edit .jobitemdetails").html(data);             }            });          },          rowtemplate: kendo.template($("#invoicerowtemplate").html()),        });     });  </script> 

datasourceresult formats server response this:

{     data: [ {jobnumber: "...", fieldname: "bar", ... } ],     total: 100 } 

in other words, data items array assigned data field, , total items count assigned total field. kendo ui datasource configuration must take account setting schema.data , schema.total:

http://docs.telerik.com/kendo-ui/framework/datasource/crud#schema

http://docs.telerik.com/kendo-ui/framework/datasource/crud#read-remote

schema: {     data: "data",     total: "total" } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -