May 17, 2011, 4:15 PM
[CLOSED] Extend store's getRecordsValues options to take in whether it should use the json property instead of data?
Hi,
Temporarily I ended up creating this code just so I could access the json property of the record, instead of the data property:
Would it be acceptable for you to extend getRecordsValues options to take in whether it should get json instead, so that the following line
I've verified that by using the above json property instead, I get back the non HTML data sent to the server successfully and therefore I can export to Excel without problem.
Temporarily I ended up creating this code just so I could access the json property of the record, instead of the data property:
Ext.data.GroupingStore.prototype.getRecordsJsonValues = function (options) {
options = options || {};
var records = (options.records ? options.records : (options.currentPageOnly ? this.getRange() : this.getAllRange())) || [],
values = [],
i;
for (i = 0; i < records.length; i++) {
var obj = {}, dataR;
dataR = Ext.apply(obj, records[i].json);
if (this.metaId()) {
obj[this.metaId()] = options.excludeId === true ? undefined : records[i].id;
}
dataR = this.prepareRecord(dataR, records[i], options);
if (!Ext.isEmptyObj(dataR)) {
values.push(dataR);
}
}
return values;
};
You will notice that it is a copy/paste of your from your data/Store.js getRecordsValues(options) method where the only difference is that instead of using records[i].data it uses records[i].json.Would it be acceptable for you to extend getRecordsValues options to take in whether it should get json instead, so that the following line
dataR = Ext.apply(obj, records[i].data);
can then become something like this: dataR = Ext.apply(obj, options.jsonRecords === true ? records[i].json : records[i].data);
Reason:- I use DataViews from time to time, and some of the XTemplates I use generate HTML in the prepareData phase, such as image tags. This is done by updating the data parameter passed to the prepareData parameter, which is what is used in the above function
- Normally we would use the correct XTemplate upfront which would have all the HTML we need as part of the template, in which case I would not need to assign HTML to the data item.
- However, our data is quite dynamic and we cannot know the XTemplate specifics for each row until we get the data, which is why only then do we render the specific HTML. And even per row of data our HTML will subtly vary within the overall XTemplate. E.g., sometimes, depending on the data you may have an image, or sometimes text, or sometimes different HTML. (And XTemplate if statements are also not enough for our scenario as pretty much all of it can be configured and data driven!)
- But by that time, the only way we can do it - as far as I can tell - is by assigning HTML to the data itself, and hence the issue during the postback (this allows our data driven solutions to be extended simply by providing new script, and not providing any new C#).
- This all renders and works fine up to this point.
- However, I also provide the ability to export the data to excel/csv, but the post back this requires now has html in it which asp.net by default will prevent processing of in fear of malicious content.
I've verified that by using the above json property instead, I get back the non HTML data sent to the server successfully and therefore I can export to Excel without problem.
Last edited by Daniil; May 20, 2011 at 12:41 PM.
Reason: [CLOSED]