I have a grid on a page and I wanna populate the grid with the results of Ajax function, but I don't know do this correctly. I already seen some examples, but I don't know how to use them in my situation. So, thanks for the help.
Ajax Function:
$.ajax({
type: "POST",
url: "../ContractManagerWS.asmx/LanguagesGet",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var result = '{ "languages": [ ';
for (var i = 0; i < data.d.length; ++i) {
result += '{ "LANG_ID": "' + data.d[i].LANG_ID + '", "LANG_DT_DEACTIVATED": "' + data.d[i].LANG_DT_DEACTIVATED + '", "LANG_TX_CODE": "' + data.d[i].LANG_TX_CODE + '", "LANG_TX_NAME": "' + data.d[i].LANG_TX_NAME + '" },';
}
console.log(result += ' ] }');
}
});
var result returns
{
"languages": [
{
"LANG_ID": "0",
"LANG_DT_DEACTIVATED": "",
"LANG_TX_CODE": "pt-BR",
"LANG_TX_NAME": "Português"
},
{
"LANG_ID": "1",
"LANG_DT_DEACTIVATED": "",
"LANG_TX_CODE": "en-US",
"LANG_TX_NAME": "English"
},
]
}
My Grid:
$("#grid").kendoGrid({
reorderable: true,
resizable: true,
columnMenu: {
filterable: false,
sortable: false
},
filterable: {
mode: "row"
},
sortable: {
mode: "multiple",
allowUnsort: true
},
scrollable: {
virtual: true
},
toolbar: ["create"],
height: 300,
columns: [
{ field: "LANG_ID", title: "ID"},
{ field: "LANG_TX_NAME", title: "Nome"},
{ field: "LANG_TX_CODE", title: "Código"},
{ command: ["Editar"], title: "Editar"},
{ command: ["Desativar"], title: "Desativar" },
{ field: "LANG_DT_DEACTIVATED", title: "Desativado em"}
],
editable: "popup"
});
setDataSource()
method. - Brettdata.d
and stringifying it when you could easily just bind it to the grid? This is wasteful. Yourdata.d
is already an array of objects with the same property names that your grid columns bind to. - Brett