Skip to content

Instantly share code, notes, and snippets.

@carrbrpoa
Last active March 24, 2021 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carrbrpoa/f888849660693aebe64a76595056b1ca to your computer and use it in GitHub Desktop.
Save carrbrpoa/f888849660693aebe64a76595056b1ca to your computer and use it in GitHub Desktop.
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
Copy link

Thanks for sharing!

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