I have CSV files stored on remote servers, and I need to display this data in an APEX Interactive Grid. Since the CSV data can have an arbitrary number of columns, is it possible to dynamically update the Interactive Grid's model after initialization?
I am retrieving this data from the backend as an array of JSON objects. While the grid and tableModelView components can easily handle this, they lack features like a toolbar, search, filters, and graphs.
References:
function loadDataToTable(odata ) {
const fieldNames = odata.detail.column_categorization.map(e=>e.columnName);
const fields = fieldNames.reduce((acc, fieldName, index) => {
acc[fieldName] = {
index: index,
heading: `<em>${fieldName}</em>`,
label:fieldName,
canHide:true,
readonly:true,
canSort:true,
hidden: false,
escape: false,
frozen: false,
noCopy: false,
sortIndex: index,
width: 120
};
return acc;
}, {});
// Call apex.model.create
apex.model.create(
"csvdata",
{
shape: "table",
recordIsArray: false,
hasTotalRecords:true,
fields: fields ,
pageSize:odata.detail.page_size,
identityField: odata.detail.defaults.primaryKey, // Assuming ID field is always present
paginationType: "one"
},odata.result, odata.result.length);
$("#assessment-data").grid({
modelName: "csvdata",
columns: [ fields ]
});
}
function fetchAssessmentData(page,pageSize) {
apex.server.process('fetch_assessment_data',
{
x01:apex.item('P7_ASSESSMENT_ID').getValue()
},
{
dataType: "text", beforeSend: function () {
console.log(apex.item('P7_ASSESSMENT_ID').getValue(), $v("pInstance"), page,pageSize)
},
success: function (pData) {
if (pData.includes('sqlerrm')) {
apex.message.clearErrors();
apex.message.showErrors([{ type: "error", location: "page", message: pData, unsafe: false }]);
} else {
let resp = JSON.parse(pData)
let odata = JSON.parse(resp.response);
console.log(odata)
odata.detail.column_categorization =JSON.parse(odata.detail.column_categorization )
odata.detail.defaults=JSON.parse(odata.detail.defaults)
loadDataToTable(odata)
}
},
error: function (pError) {
apex.message.clearErrors();
apex.message.showErrors([{ type: "error", location: "page", message: pError, unsafe: false }]);
},
complete: function (pError) {
},
timeout: 3000
});
}