问题
ag-grid sorting is not working with another third party plugin. Stimulsoft report.js for reporting tool.
please find plunkr link for the same.
<html>
<head>
<script src="https://unpkg.com/ag-grid@13.3.1/dist/ag-grid.js"></script>
<script src="https://cdn.jsdelivr.net/npm/stimulsoft-reports-js@2018.2.3/stimulsoft.reports.js"></script>
</head>
<body>
<div id="myGrid" style="height: 100%;" class="ag-fresh"></div>
<script src="main.js"></script>
</body>
</html>
回答1:
Your problem is likely due to the fact that "Stimulsoft Reports.JS" heavily modifies the native prototypes (String
/ Array
/Object
, at least) in JavaScript, which is almost always a terrible idea.
Their code is bad, in other words.
Here are some supporting links:
- Why is extending native objects a bad practice?
- Why is it frowned upon to modify JavaScript object's prototypes?
- http://perfectionkills.com/extending-native-builtins/
As for how to fix it, no idea. It's a long investigation to figure that out.
Try putting the Stimulshaft stuff in a iframe
so it can be nice and happy alone to pollute itself.
I'm not even certain that this is the cause, but it probably is. It might be that there's something ag-grid can do to fix it on their end, but it's not their problem. Whatever is happening, it's Stimulshaft's fault.
回答2:
in ag-grid
ComponentUtil.toNumber = function(value) {
if (typeof value === 'number') {
return value;
} else if (typeof value === 'string') {
return Number(value);
} else {
return undefined;
}
}
and in stimulsoft
Object.prototype.toNumber = function() {
if (this.sti_is(String) && this.indexOf(",") >= 0)
return Number(this.replaceAll(",", "."));
return Number(this)
}
so due to this conflict sorting is not able to do.
then i added below lines then solved my issue.
<script>
Object.prototype.toNumber = undefined;
</script>
来源:https://stackoverflow.com/questions/51592044/ag-grid-sorting-is-not-working-with-another-third-party-plugin