0

I'm very new to JQuery, and I'm having some trouble

function Clients(guid)
{
 var that = this;

this.guid = guid;
this.container = $("#Clients_" + that.guid);

this.LoadClients = function () {
 var ids = that.container.find("#clients-tbl").getDataIDs();

    for (var i = 0; i < ids.length; i++) {
        var row = that.container.find("#clients-tbl").getRowData(ids[i]);

        var imgView = "<img src='../../Content/Images/vcard.png' style='cursor:pointer;' alt='Open case' onclick=OnClickImage(" + ids[i] + "); />";

        that.container.find("#clients-tbl").setRowData(ids[i], { CasesButtons:  imgView });
    }
}


this.CreateClientsGrid = function () {
    var clientsGrid = that.container.find("#widget-clients-tbl").jqGrid({
.....
 ondblClickRow:function(rowid)
{
   ---
}
  loadComplete: function () {
            that.LoadClients();


        }
 }
 this.OnClickImage=function(idClient){
  ....
 }

 this.Init = function () {
    that.CreateClientsGrid();
};

this.Init();
}

The problem is with onclick, because OnClickImage is not global function. How can I use OnClickImage function?

cashmere
  • 885
  • 3
  • 12
  • 37

1 Answers1

0

You can bind to the click event in different ways. For example you can follow the way from the answer. By the way, it works much more quickly as getRowData and setRowData. Moreover you should save the result of that.container.find("#clients-tbl") operation in a variable outside of the loop and use use the variable inside the loop. JavaScript is dynamic language and every operation even ids.length will be done every time.

One more way would to use onCellSelect event without click event binding. See the answer which describe the approach and gives the corresponding demo.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • With event onCellSelected, I have problem with ondblClickRow. – cashmere Aug 02 '11 at 14:16
  • @cashmere: What problem you have with `ondblClickRow`? You can use `beforeSelectRow` instead of `onCellSelected`. You should don't forget to return `true` from the `beforeSelectRow`. You should explain the problem more clear if you want to solve the problem. Posting of the code is the best. – Oleg Aug 02 '11 at 14:37