I am using alfresco 5.0.d version needs to populate the custom model properties in YUI datatable and in response I am getting the JSON as below.
{"agency" : [
{
"agencyname": "1212",
"agencycode": "1212",
"createDate": "23/03/2016"
}
]
}
custom-users-min.js file: Generating the request and populating the resultlist.
var an = [
{
key : "agencyname",
label : Q._msg("label.agencyname"),
sortable : true
},{
key : "agencycode",
label : Q._msg("label.agencyCode"),
sortable : true
}, {
key : "createDate",
label : Q._msg("label.createdDate"),
sortable : true
}
];
var ar = this;
var am = Q;
Q.widgets.pagingDataTable = new Alfresco.util.DataTable({
dataTable : {
config : {
generateRequest : function (ay, aA) {
var aC = (ay.pagination.page - 1) * ay.pagination.rowsPerPage;
var az = encodeURIComponent((ay.sortedBy) ? ay.sortedBy.key : aA.getColumnSet().keys[0].getKey());
var ax = (ay.sortedBy && ay.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc";
am.widgets.pagingDataTable.currentSortKey = az;
am.widgets.pagingDataTable.currentDir = ax;
var aB = "?sortBy=" + az + "&dir=" + ax;
if (Q.searchTerm) {
aB = aB + "&filter=" + encodeURIComponent(Q.searchTerm) + "&startIndex=" + aC + "&pageSize=" + ay.pagination.rowsPerPage
}
return aB
}
},
container : Q.id + "-datatable",
columnDefinitions : an
},
dataSource : {
url : Alfresco.constants.PROXY_URI + "api/customagencysearch",
pagingResolver : function (ay, aA, ax, az) {
return "startIndex=" + ay + "&pageSize=" + aA + "&" + ar._buildSearchParams(Q.searchTerm).substring(1) + "&sortBy=" + ax + "&dir=" + az
},
config : {
responseType : YAHOO.util.DataSource.TYPE_JSON,
responseSchema : {
resultList:"agency"
//resultFields: [ 'agencycode', 'agencyname', 'createDate']
}
}
},
paginator : {
history : false,
hide : false,
config : {
containers : [Q.id + "-paginator"],
rowsPerPage : Q.options.maxSearchResults
}
}
});
customagency.lib.ftl file:
<#macro agencyJSON agency>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"agency" : [
<#list agency as result>
{
"agencyname": <#if result.properties["agency:agencyname"]??>"agencyname"<#else>"agencyname"</#if>,
"agencycode": <#if result.properties["agency:agencycode"]??>"agencycode"<#else>"agencycode"</#if>,
"createDate": <#if result.properties["agency:createDate"]??>"${result.properties["agency:createDate"]?string('dd/MM/yyyy')}"<#else>"23/03/2016"</#if>
}
<#if result_has_next>,</#if>
</#list>
]
}
</#escape>
</#macro>
customagency.get.json.ftl file:
<#import "customagency.lib.ftl" as customagencyLib/>
<@customagencyLib.agencyJSON agency=agency/>