I solved my problem.
I hope that my guide can help someone in the future!!
1): I found my solution in these two links :
http://www.jeasyui.com/forum/index.php?topic=1774.0http://www.jeasyui.com/forum/index.php?topic=286.02) I created a specific function to retrieve json data from php script:
- the php script is divide by two parts: to retrieve rows data and to retrieve columns name.
- the javascript ask the type of data by posting the request (row or column)
- parsing of json data, for the columns, to build the array like specification (array of array ad index without quotes):
[[{field:'field_value_1', title:'Title_of_field_1'},{field:'field_value_2', title:'Title_of_field2'}]]
The code:
function loadData(frm){
var colStruct = [];
var colItems = [];
colStruct.pop();
$.getJSON(getParameters(frm,'columns'),function(data){ <=== the function getParameters takes the data values from a form and it ask to retrieve columns name. PHP return a JSON array
var obj = data.columns; <== the json array :{"columns":{"field1","field2",...,"fieldn"}}
for (var value in obj){ <== let's start to buil our column object
var menuItem = {
field: obj[value],
title: obj[value], <== index without quotes!!!
align: 'center'
};
colItems.push(menuItem); <== here we push the column object into the array
}
colStruct.push(colItems); <== then push the column array in other array
$('#dg').datagrid({
columns: colStruct,
url:getParameters(frm,'rows') <=== In this case I want to have rows data... so I ask row data and then PHP return to me a JSON array with the data that I want
});
});
}
This is my solution.
If someone have a better idea or want to improve my solution, please write!! :-)