2013-02-16 28 views
0

我很习惯于使用KendoUI网格插件,但是我遇到了一个新的场景,我需要来自我的数据库的列参数。如何获得从数据库传递的列参数

通常的设置是:

columns: 
    [ 
    { 
    field: "username", 
    width: 247, 
    title: "Name" 
    }, 
    { 
    field: "branch", 
    width: 50, 
    title: "Branch", 
    }... 

我现在需要这些参数来让我的PHP脚本来确定。

有什么我需要在我的dataSource参数中设置?如果可以,请给我一个例子?

仅供参考这里是我的数据源参数:

dataSource: { 
    serverPaging: true, 
    serverSorting: true, 
    pageSize: 5, 
    transport: { 
     read: { 
     url: ROOT+"user/user-list", 
     }, 
     update: { 
     url: ROOT+"user/update-user", 
     type: "POST", 
     data: function(data) 
     { 
      data.DoB = kendo.toString(data.DoB, 'yyyy-MM-dd') ; 
      data.dateStarted = kendo.toString(data.dateStarted, 'yyyy-MM-dd') ; 
      return data; 
     } 
     } 
    }, 
    error: function(e) { 
     alert(e.errorThrown+"\n"+e.status+"\n"+e.xhr.responseText) ; 
    }, 
    schema: { 
     data: "data", 
     total: "rowcount", 
     model: { 
     id: 'id', 
     fields: { 
      username: { 
      type: "string", 
      editable: true 
      }, 
      type: { 
      type: "string", 
      editable: true, 
      validation: { 
       required: true 
      } 
      }, 
      level: { 
      type: "string", 
      editable: true, 
      validation: { 
       required: true 
      } 
      }, 
      firstName: { 
      type: "string", 
      editable: true 
      }, 
      middleName: { 
      type: "string", 
      editable: true 
      }, 
      lastName: { 
      type: "string", 
      editable: true 
      }, 
      DoB: { 
      type: "date", 
      editable: true, 
      format: "{0:yyyy/MM/dd}" 
      }, 
      dateStarted: { 
      type: "date", 
      editable: true, 
      format: "{0:dd/MM/yyyy}" 
      }, 
      enabled: { 
      type: "boolean", 
      editable: true 
      } 
     } 
     } 
    } 
    } 

回答

0

我才意识到我可以用$就以填补JSON格式的列数据的变量做到这一点。

例如,调用初始化前栅格如下:

网格
var columnData ; 
$.ajax({ 
url: myDataSource, 
type: 'POST', 
success: function(data){ 
columnData = data ; // In the form of [{field: "username",width: 247,title: "Job #"}] 
}) 
}) 

然后:

... 
columns: columnData 
... 

我是过于复杂的事情。欢迎任何评论。