ag-grid sorting is not working with another third party plugin

别说谁变了你拦得住时间么 提交于 2019-12-13 08:17:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!