2013-11-24 2 views
0

Спокойной ночи! Я перехожу к модели схемы сетки kendo ui и поле типа даты, но это происходит в настройках фильтра, когда я нажимаю, просто показывает операторов, которые работают со строкой, выглядя, как будто он просто идентифицирует это поле как строку! Может кто-нибудь мне помочь?Дата оператора в кендо ui Сетка не получает вид

<script> 
      $(document).ready(function(){}) 
      function getData(page) 
      { 
       data = page.split("||"); 
       //data = $.parseJSON(page); 
       //alert(data.toSource()); 
       //alert(JSON.parse(page)); 
       return {data: JSON.parse(data[1]), total: data[0]}; 
       //return JSON.parse(page); 
      } 
      $(document).ready(function() { 

       var windowTemplate = kendo.template($("#windowTemplate").html()); 

       var window = $("#window").kendoWindow({ 
        title: "Are you sure you want to delete this record?", 
        visible: false, //the window will not appear before its .open method is called 
        modal: true, 
        resizable: false, 
        draggable: false, 
        width: "400px", 
        height: "200px", 
       }).data("kendoWindow"); 



       var grid = $("#grid").kendoGrid({ 
        dataSource: { 
         serverPaging: true, 
         serverFiltering: true, 
         serverSorting: true, 
         batch: true, 
         pageSize: 3, 
         schema: { 
          data: "data", 
          total: function(e){ 
           //alert(e.toSource()); 
           return e.total; 
          }, 
          model: { id: "id_turma" }, 
            fields: { 
             id_turma: { editable: false, nullable: true }, 
             nome_turma: { validation: { required: true } }, 
             sigla_turma: { validation: { required: true, max:12 }, 
             data_criacao: { editable: true,type:"date", format: 'dd/MM/yyyy' }} 
            } 
         }, 
         transport: { 
          read: function (option) { 
           $.ajax({ 
            url: '<?=$view->encode('ctrl.php?turma=lista_turma');?>', 
            type: "POST", 
            data: 
            { 
             skip: option.data.skip, 
             take: option.data.take, 
             pageSize: option.data.pageSize, 
             page: option.data.page, 
             sorting: JSON.stringify(option.data.sort), 
             filter: JSON.stringify(option.data.filter) 
            }, 
            success: function (result) { 
             var data = getData(result); 
             option.success(data); 
            }, 
            error: function (err) { 
             alert(err.toSource()); 
            } 
           }); 
          } 
         } 
        }, 
        //sortable: true, 
        sortable: { 
         mode: "multiple", // enables multi-column sorting 
         allowUnsort: true 
        }, 
        pageable: { 
         refresh: true, 
         pageSizes: [5, 10, 20, 50, 100], 
         buttonCount: 2 
        }, 
        selectable: true, 
        filterable: true, 
        columnMenu: true, 
        height: 350, 
        groupable: true, 
        toolbar: [{name:"create",text:"Adicionar"}], 
        columns: [ 
         { field:"nome_turma", title: "Nome"/*, filterable: false*/ }, 
         { field: "sigla_turma", title:"Sigla", width: "100px" }, 
         { 
          field: "data_criacao", 
          title: "Date create", 
          type: "date", 
          format: '{0:dd/MM/yyyy}', 
          template: "#= kendo.toString(kendo.parseDate(data_criacao, 'yyyy-MM-dd'), 'dd/MM/yyyy') #", 
          filterable: { 
           ui: "datepicker", 
           format: '{0:dd/MM/yyyy}' 

          } 
         }, 
         { 
          command:[ 
          { 
           name: "edit", 
           text: { 
            edit: "Editar",    // This is the localization for Edit button 
            update: "Salvar",    // This is the localization for Update button 
            cancel: "Cancelar" // This is the localization for Cancel button 
           } 
          }, 
          { 
           //className: "btn-apagar", 
           name: "destroy", 
           text: "Apagar", 
           click: function(e) { 
            alert('sdadsdsadsadsa'); 
            var tr = $(e.target).closest("tr"); //get the row for deletion 
            var data = this.dataItem(tr); //get the row data so it can be referred later 
            window.content(windowTemplate(data)); //send the row data object to the template and render it 
            window.open().center(); 

            $("#yesButton").click(function(){ 
             grid.dataSource.remove(data) //prepare a "destroy" request 
             grid.dataSource.sync() //actually send the request (might be ommited if the autoSync option is enabled in the dataSource) 
             window.close(); 
            }) 
            $("#noButton").click(function(){ 
             window.close(); 
            })           
           } 
          } 
          ]} 

          //{ command: { text: "ManageEvent", click: showDetails }, title: " Edit Event", width: "60px" }, 
         ], 
        editable : { 
         mode : "popup", 
         update: true, 
         destroy: false, 
         template: $("#popup_editor").html(), 
         window : { 
          title: "Edit Office",   // Localization for Edit in the popup window 
         } 
        } 
       }); 
      }); 

     </script> 

ответ

0

С помощью следующего кода в чтение может передать фильтр, какой тип поля отправляется.

read: function(option) { 

        if (option.data.filter !== undefined) { 
         var fields = source.options.schema.model.fields; 
         //alert(option.data.filter.filters.length); 
         for (var i = 0; i < option.data.filter.filters.length; i++) { 
          var name = option.data.filter.filters[i].field; 

          if (fields[name].type === "date") { 
           //Format date 
           option.data.filter.filters[i].value = kendo.toString(option.data.filter.filters[i].value,"yyyy-MM-dd"); 
          } 
          //add type at filter get type of schema 
          option.data.filter.filters[i].type = (fields[name].type)?fields[name].type:"string"; 
         } 
... 
0

Вам нужно определить поле даты в схеме из источника данных:

schema: { 
    model: { 
     fields: { 
      data_criacao: { type: "date" } 
     } 
    } 
}, 
+0

Если вы посмотрите на код, который я разместил, я уже сделал это –

+0

Извините, я этого не видел. Обычно источник данных определяется первым. –

0

я переехал в части DATASOURCE следующим образом:

dataSource: new kendo.data.DataSource({ 
         transport: { 
          read: function (option) { 
           $.ajax({ 
            url: '<?=$view->encode('ctrl.php?turma=lista_turma');?>', 
            //type: "POST", 
            //dataType: "json", 

            data: 
            { 
             skip: option.data.skip, 
             take: option.data.take, 
             pageSize: option.data.pageSize, 
             page: option.data.page, 
             sorting: JSON.stringify(option.data.sort), 
             filter: JSON.stringify(option.data.filter) 
            }, 
            success: function (result) { 
             var data = getData(result); 
             //var data = getData(result); 
             option.success(data); 
            }, 
            error: function (err) { 
             alert(err.toSource()); 
            } 
           }); 
          }, 
          parameterMap: function(options, operation) { 
           if (operation !== "read" && options.models) { 

            return {models: kendo.stringify(options.models)}; 
           } 
          } 
         }, 
         serverPaging: true, 
         serverFiltering: true, 
         serverSorting: true, 
         batch: true, 
         pageSize: 3, 
         schema: { 
          data: function(data){ 
           return data.data; 
          }, 
          total: function(data){ 
           return data.total; 
          }, 
          model: { 
           id: "id_turma" , 
           fields: { 
            id_turma: { editable: false, nullable: true }, 
            nome_turma: { validation: { required: true } }, 
            sigla_turma: { validation: { required: true, max:12, min: 2 }}, 
            data_criacao: { editable: true,type:"date", format: 'dd/MM/yyyy' } 
           } 
          } 
         } 
        }), 
Смежные вопросы