剑道网格只返回一条记录

时间:2015-03-06 16:06:58

标签: kendo-ui kendo-grid

我一直在网上搜索找到这个问题的答案,但没有成功,我的问题是我的Kendo ui网格只返回一条记录。有趣的是,我有另一个网格正确返回所有记录,所以我只是使用相同的代码,但有一个细节,逃避我所以我跳跃有人可以指出,这是代码我正在使用(CRUD):

var dataSource = new kendo.data.DataSource({
        transport: 
        {
          read:  
            {
              url: "data/clientes.php",      
            },

          update: 
            {
              url: "data/clientes.php?type=update",
              type:"POST",
              complete: function(e) 
              {  
                $("#gridClientes").data("kendoGrid").dataSource.read(); 
              }
            },

          destroy: 
            {
              url: "data/clientes.php?type=destroy",
              type: "POST"
            },

          create: 
            {
              url: "data/clientes.php?type=create",
              type: "POST",
              complete: function (e) {
                $("#gridClientes").data("kendoGrid").dataSource.read();
            }

            },

            parameterMap: function(options, operation) 
            {
                if (operation !== "read" && options.models) 
                {
                    return {models: kendo.stringify(options.models)};
                }
            }                      
        },

        error:function(e)
        {
          console.log(e);
          //alert(e.message);
        },
        batch: true,
        pageSize: 8,
        schema: 
        {
          data: "data",
            total: function(response) 
            {
              return $(response.data).length;
            },
            model: 
            {
              id: "idCliente",

              fields: 
              {
                idCliente: { editable: false, nullable: true, type: "number"},
                titulo: { validation: { required: false } },
                primeiroNome: { validation: { required: true } },
                ultimoNome: { validation: { required: true } },
                morada: { validation: { required: false } },
                codigoPostal: { type: "string",validation: { required: false} },
                cidade: { validation: { required: false } },
                pais: { validation: { required: false } },
                estado: { validation: { required: false } },
                telefone: { type: "string", validation: { required: false, min: 1} },
                email: { validation: { required: false } },
                passaporte: { validation: { required: false } },
                bi: { type: "number", validation: { required: false} },
                foto: { type: "string", validation: { required: false} },
                comentarios: { validation: { required: false } },
                NomeUtilizadorCriador: {editable: true,validation: { required: false } },
                DataCriacao: {editable: false,  validation: { required: false } },
                NomeUtilizadorUpdate: {editable: true, validation: { required: false } },
                DataUpdate: {editable: false,  validation: { required: false } },
              }
           }
        }
      });

      $("#gridClientes").kendoGrid({
          dataSource: dataSource,            
          height: 550,
          serverPaging: true,
          pageable  : true,
          toolbar:[{name: "create",text: $varGridQuartosBtnNovoPT},{name: "close",text: "X"}],
          editable  : {mode : "popup",               
            window : {title: "Editar",}
          },
          columns: [
                  { field: "titulo", title: "Título", width: "8px", },
                  { field: "primeiroNome", title: "Primeiro Nome", width: "14px" },
                  { field: "ultimoNome", title: "Ultimo Nome", width: "14px" },
                  { field: "morada", title: "Morada", width: "11px" },
                  { field: "cidade", title: "Cidade", width: "11px" },
                  { field: "codigoPostal", title: "CEP", width: "9px", editor:numberEditor },
                  { field: "pais", title: "País", width: "14px" ,editor: paisEditor},
                  { field: "estado", title: "Estado", width: "10px", hidden: true },
                  { field: "telefone", title: "Telefone", width: "12px",editor:numberEditor},
                  { field: "email", title: "Email", width: "17px" },
                  { field: "passaporte", title: "Passaporte", width: "15px", hidden: true },
                  { field: "bi", title: "Bi", width: "10px", hidden: true ,editor:numberEditor},
                  { field: "foto", title: "Foto", hidden: true, editor:fotoEditor},
                  { field: "comentarios", title: "Comentários", hidden: true, editor: textareaEditor},
                  { field: "NomeUtilizadorCriador", title: "Criado por", hidden: true,editor:numberEditor},
                  { field: "DataCriacao", title: "Criado em", hidden: true, width: "10px"},
                  { field: "NomeUtilizadorUpdate", title: "Atualizado por", hidden: true, editor:numberEditor},
                  { field: "DataUpdate", title: "Atualizado em", hidden: true, width: "10px"},
                  {command:[{ text: "Detalhes", click: showDetails },{ name: "edit",text:"Editar"},{ name: "destroy",text:"Apagar"}],title:" ",width: "30px"}],

});

如果我的数据库是空的并且我只插入一条记录,那么它会正确地返回该记录,但如果我点击新按钮插入另一条记录,它会插入数据库但是kendo网格什么都不返回,同时我发现这个kendogrid与其他人(正常工作)之间的区别当我打开chrome控制台时,这个返回两个对象“data”:

0: {,…}
data: {0: "70", 1: "", 2: "jonh", 3: "sousa", 4: "", 5: "", 6: "", 7: "", 8: "", 9: "", 10: "", 11: "",…}

1: {,…} 
data: {0: "73", 1: "", 2: "joana", 3: "banana", 4: "", 5: "", 6: "", 7: "", 8: "", 9: "", 10: "", 11: "",…}

其他kendogrids,只返回一个对象数据,为什么?我不知道,因为我使用相同的代码。我以为它可能与我的.php文件有关,但如果是的话,它甚至不应该插入一条记录吗?

我在调用网格时也遇到此错误:

Object {xhr: Object, status: "parsererror", errorThrown: SyntaxError: Unexpected end of input, sender: ht.extend.init, _defaultPrevented: false…}

当我的数据库为空时出现此错误。如果我有一条记录,那么错误就会消失,正如我在网格正确显示之前说的那样,但如果我插入另一条记录,则错误会返回。

对不起,很长的帖子,谢谢你的时间,任何帮助都将非常感谢。

此致

0 个答案:

没有答案