1

i use kendo ui grid (for asp.net mvc) without problem if i declare dataSource transport read as url like:

var dataSource = {
   pageSize: 20,
   batch: true,
   serverOperation: true,
   serverPaging: true,
   serverSorting: true,
   serverFiltering: true,
   type: "aspnetmvc-ajax",
   transport:
   {
      read:
      {
         url: '/Home/GetNodes',
         type: "POST",
         dataType: "json",
         data: function ()
         {
            return {'p1': 'some text', 'p2': 'other'}
         }
      }
   }
};

now the problem is that i want do use function mode read (is a software design requirement) but the sintax used to pass request parameters to server differ from use transport type "aspnetmvc-ajax" or not. if i set transport type "aspnetmvc-ajax" the read function is not fired, but if not set transport type "aspnetmvc-ajax" the request parameter is not passed well on server side!

if i watch the post parameters sent via http:

with transport type "aspnetmvc-ajax":

page:1
pageSize:20
sort:Field1-asc
filter:Field1~eq~'value1'

without transport type "aspnetmvc-ajax":

page:1
pageSize:20
sort:[{field:Field1, dir:asc}]
filter:{filters:[{operator:eq, value:value1, field:Field1}], logic:and}

sort and filter value parameters differ from "aspnetmvc-ajax" version and server-side are null!

as workaround i manually parse the request params inside parameterMap as shown on bottom, translating sort and filter value sintax compliance with "aspnetmvc-ajax" version and server side are passed well.

  • there is a best solution?
  • why if i use "aspnetmvc-ajax" transport type the read function is not invoked?
  • if the only solution to use read function is to avoid using "aspnetmvc-ajax" transport type, there is a standard way to format request parameters for use on server side in DataSourceRequest object?

thanks

attually my workaround is:

var dataSource = {
   pageSize: 20,
   batch: true,
   serverOperation: true,
   serverPaging: true,
   serverSorting: true,
   serverFiltering: true,
   transport:
   {
      read: function (options)
      {
         var request = $scope.grdDocuments.dataSource.transport.parameterMap({
             filter: $scope.grdDocuments.dataSource.filter(),
             group: $scope.grdDocuments.dataSource.group(),
             sort: $scope.grdDocuments.dataSource.sort(),
             page: $scope.grdDocuments.dataSource.page(),
             pageSize: $scope.grdDocuments.dataSource.pageSize()
         });

         httpService.GetNodes(request.filter, request.group, request.sort, request.page,    request.pageSize, sFolderId, ... other parameters)
         .then(
         function (args)
         {
             //Verifica esito della richiesta http
             if (!sharedService.CheckHttpRequestResult(args, 'GetNodes'))
             {
                 options.error(null);
                 return;
             }

             options.success(args.data);
         }
         );
      },
      parameterMap: function (data, operation)
      {
         //Trasformazione parametro filter
         if (typeof data.filter !== 'undefined')
         {
            //normale: {filters:[{operator:eq, value:a, field:Affidatario}], logic:and}
            //trasformato: Affidatario~eq~'a'
            var filter = '';
            for (var i = 0; i < data.filter.filters.length; i++)
            {
               if (filter !== '')
                  filter += '~' + data.filter.logic + '~';

               var fieldValue = "'" + data.filter.filters[i].value + "'";

               //Formattazione valore in base al formato della colonna
               var found = model.fields[data.filter.filters[i].field];
               if (typeof found !== 'undefined')
               {
                  if (found.type === 'number')
                     fieldValue = data.filter.filters[i].value;
                  else if (found.type === 'date')
                     fieldValue = "datetime'" + data.filter.filters[i].value.format('Y-m-d') + "T00-00-00'";
               }

               filter += data.filter.filters[i].field + '~' + data.filter.filters[i].operator + '~' + fieldValue;
            }
            data.filter = filter;
         }

         //Trasformazione parametro sort
         if (typeof data.sort !== 'undefined')
         {
            //normale: [{field:Anno, dir:asc}]
            //trasformato: Anno-asc
            var sort = '';
            for (var i = 0; i < data.sort.length; i++)
            {
               if (sort !== '')
                  sort += '~';

               sort += data.sort[i].field + '-' + data.sort[i].dir;
            }
            data.sort = sort;
         }

         var result = JSON.parse(JSON.stringify(data));
         return result;
      }
   }
};

server side:

public JsonResult GetNodes([DataSourceRequest]DataSourceRequest request, string sFolderId, ... other parameters)
{

}

1 Answer 1

1

Just in case someone else stumbles across this post like I did today. This might help you

For me the answer was the line

var data = kendo.data.transports["aspnetmvc-ajax"].prototype.options.parameterMap.call(this, optionsData.data, "read", false);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.