Skip to content

Instantly share code, notes, and snippets.

@carrbrpoa

carrbrpoa/AttributesTable\Table.js Secret

Last active Mar 24, 2021
Embed
What would you like to do?
cmv-app / Search widget / way to add table with data provided by a previously loaded json
...
executeQueryTask: function (options) {
(...)
var qp = this.getQueryParameters(options);
(...)
var url = this.getQueryTaskURL();
if (!url) {
//CUSTOM
this.processQueryResults(options.queryOptions.queryParameters.data);
return;
}
(...)
}
...
processQueryResults: function (results) {
this.clearGrowl();
this.executingQuery = false;
if (!results) {
return;
}
// CUSTOM
if (!results.features && results[0]) {
results = {
fields: Object.keys(results[0]).map(k => {
return {
name: k,
type: 'esriFieldTypeString' // yes, hardcoded for now..
}
}),
features: results.map(r => {
return {
attributes: r
}
}),
spatialReference: {}
}
}
(...)
}
...
postCreate: function () {
this.inherited(arguments);
(...)
} else if (this.findOptions && this.findOptions.url) {
this.own(aspect.after(this, 'startup', lang.hitch(this, function () {
this.executeFindTask(options);
})));
} else if (this.queryParameters && this.queryParameters.data) { //CUSTOM else if
this.own(aspect.after(this, 'startup', lang.hitch(this, function () {
this.executeQueryTask(options);
})));
}
}
...
{
field: '_fancyJsonField',
label: 'Fancy Field',
renderCell: function (object, value, node) {
on(node, 'click', function () {
topic.publish('attributesContainer/addTable', {
title: 'Fancy Field in a Table',
topicID: 'resultsQuery123',
queryOptions: {
queryParameters: {
type: 'database', // ??
data: object._fancyJsonField // CUSTOM
},
idProperty: 'prop1'
},
gridOptions: {
columns: [
{
field: 'prop1',
label: 'Prop. 1'
},
{
field: 'prop2',
label: 'Prop. 2'
}
(...)
]
}
});
});
node.innerHTML = '<i class=\'fa fa-search-plus\' style=\'margin-left:8px;\'></i>'; //optional..
}
}
...
@ERS-Long2

This comment has been minimized.

Copy link

@ERS-Long2 ERS-Long2 commented Mar 24, 2021

Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment