Skip to content Skip to sidebar Skip to footer

How To Call This Onclick Javascript Function In My Architecture

I am using this article of architecture http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/ In my one class of Dashboardgrid i have two functions are : ,linkRenderer :

Solution 1:

Your scope is messed up, when the function in your <a> tag is called this does not point to your object where you defined the function but to your <a>-dom node.

It's pretty hard to call member functions from within a html fragment like the fragment returned by a grid renderer. I suggest you take a look at Ext.grid.ActionColumn to solve this problem. When you look at the code in this column type you should be able to write your own column type that renders a link instead of an icon like the ActionColumn.

Another option is using my Ext.ux.grid.ButtonColumn which doesn't render links but buttons in your grid.

more info on scope in ExtJS (and js in general): http://www.sencha.com/learn/Tutorial:What_is_that_Scope_all_about

Solution 2:

this.resellerwindow is not a function 

because 'this', in the onclick function is in fact a reference to the 'a' dom element;

In order to access the 'resellerwindow' function from the onclick handler, you need to make the function accessible from the global scope, where your handler is executed:

var globalObj = 
{
    linkRenderer : function (data, cell, record, rowIndex, columnIndex, store) 
    {
        if  (data != null)              
            return'<a href="javascript:void(0)" onclick="globalObj.resellerwindow(\''  +record.data.cityname+'\')">'+ data +'</a>';        
        returndata;
    },
    resellerwindow : function (cityname) 
    {
        // render the grid to the specified div in the page// resellergrid.render();
        resellerstore.load();
        wingrid.show(this);
    } 
}  

so use the globalObj.resellerwindow(......);

Solution 3:

The problem is that this does not point to the class itself. Should you need to render the a element as a string instead of JavaScript object you will need to call a global function in which to call the resellerwindow function (after obtaining correct reference). However, I believe a much more efficient way would be to abandon the string and use JavaScript object instead. Then you can do something like the following:

var a = document.createElement("a");
    a.onclick = this.resselerwindow;

If you use jQuery something like the following can be used:

return $("<a />").click(this.resselerwindow)[0];

Solution 4:

instead of building and passing direct html, try these.

  1. Create Anchor object

{ tag: 'a', href: '#', html: 'click me', onclick: this.resellerWindow }

  1. Make sure that, scope in linkRenderer is grid, by settings 'scope: this' in that column definition. So that this.resellerWindow refers to grid's function.

  2. try returning created object.

Post a Comment for "How To Call This Onclick Javascript Function In My Architecture"