or
$(
"#JobAttachments"
).kendoGrid({
columns: [
{ title:
"Filename"
, template:
"<a href='../UploadedFiles/${ SavedFileName }'>${ OriginalFileName }</a>"
, width:
"250px"
},
{ field:
"EnterBy"
, title:
"Uploaded By"
, width:
"200px"
},
{ command:
"destroy"
, title:
"Delete"
, width:
"100px"
}
],
toolbar: [
"save"
,
"cancel"
],
// specify toolbar commands
editable:
true
,
// enable editing
dataSource: {
schema: {
data:
"d"
,
// ASMX services return JSON in the following format { "d": <result> }. Specify how to get the result.
model: {
// define the model of the data source. Required for validation and property types.
id:
"JobTaskId"
,
fields: {
AttachmentID: { editable:
false
, nullable:
false
},
JobId: { editable:
false
, nullable:
false
},
OriginalFileName: { editable:
false
},
SavedFileName: { editable:
false
},
AttachmentType: { },
Notes: { },
EnterBy: {}
//,
//EnterDate: { type: "date"}
}
}
},
batch:
false
,
// enable batch editing - changes will be saved when the user clicks the "Save changes" button
transport: {
create: {
url:
"../WebServices/JobAttachmentWebservice.asmx/NotUsed"
,
contentType:
"application/json; charset=utf-8"
,
// tells the web service to serialize JSON
type:
"POST"
//use HTTP POST request as the default GET is not allowed for ASMX
},
read: {
url:
"../WebServices/JobAttachmentWebservice.asmx/Read"
,
contentType:
"application/json; charset=utf-8"
,
// tells the web service to serialize JSON
type:
"POST"
//use HTTP POST request as the default GET is not allowed for ASMX
},
update: {
url:
"../WebServices/JobAttachmentWebservice.asmx/Update"
,
contentType:
"application/json; charset=utf-8"
,
// tells the web service to serialize JSON
type:
"POST"
//use HTTP POST request as the default GET is not allowed for ASMX
},
destroy: {
url:
"../WebServices/JobAttachmentWebservice.asmx/Delete"
,
contentType:
"application/json; charset=utf-8"
,
// tells the web service to serialize JSON
type:
"POST"
//use HTTP POST request as the default GET is not allowed for ASMX
},
parameterMap:
function
(data, operation) {
if
(operation !=
"read"
) {
// web service method parameters need to be send as JSON. The Create, Update and Destroy methods have a "products" parameter.
return
JSON.stringify({ jobView: data.models })
}
else
{
return
JSON.stringify({ JobId: currentJobId })
}
}
}
}
});
<
div
style
=
"height: 35px"
></
div
>
<
div
id
=
"clientsDb"
>
<
div
id
=
"grid"
></
div
>
</
div
>
<
script
type
=
"text/javascript"
>
$(function(){
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: {url: "read", datatype: "json", contentType: 'application/json'}
},
schema: {
model: {
fields: {
CompanyName: {type: "string"},
ContactName: {type: "string"}
}
}
},
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
height: 250,
filterable: true,
sortable: true,
pageable: true,
columns: [
{field: "CompanyName", title: "Company Name"},
{field: "ContactName", title: "Contact Name"}
]
});
});
</
script
>
public function action_read()
{
$query = DB::select("ContactName","CompanyName")->from("customers")->offset(0)->limit(10);
$accounts = $query->execute("northwind");
$toSend = array();
foreach($accounts as $acc){
$toSend[] = $acc;
}
// $data = "{\"results\":". json_encode($toSend)."}";
$data = json_encode($toSend);
$this->auto_render = false;
echo $data;
}