0

I have a jqgrid component inside my page and the rows of the grid are create with values and actions, for example:

colum:  name     adresss      job               edit

row 1:  jorge    my adress    architect        [value]

I populate the grid with several rows from a database and aech row have a value in column edit to the personal page for editing actions.

this value have this structure:

<div><span class="edit" idperson="' + items[i].id + '">Edit</span></div>

in the same script I put this:

$('.edit').live('click', this.clickedit);

and the function is:

clickedit: function(){

    $.ajax('person/personedit.htm', {
        cache: false,
        type : 'POST',
        data : { idperson: $(this).attr('idperson')},
        success : function(response){
            //some actions.....
        }
    });





},

in my java code I have a spring controller that recieve this call from jquery and do something.

The first time I clic the Edit action in a row all is OK, but after a while working with the application I see that a single edit action is called several times so the clickedit function execute 2, or 3 or 4 times and my java code are hit the same numbers of times.

any idea about this issue???

UPDATE:

I start to using onCellSelect now. But I have a problem. In a single cell I can put 3 differents action in this way:

var actions = 'editedOK ? '<div><span class="edit1" idperson="' + items[i].id + '" >EDITOK1&nbsp;&nbsp;</span><span class="edit2" idperson="' + items[i].id + '">EDITOK2</span></div>' : '<div><span class="editnook1" idperson="' + items[i].id + '">EDITNOOK1</span></div>'; 

if actions = true I see in the same cell "EDITOK1 EDITOK2" and if actions = false I see in this cell "EDITNOOK1"

everyone of this actions have associates functions with differents behaviour when I clic in it.

If I use onCellSelect it´s possible to determinate when I hit EDITOK1, when I hit EDITOK2 and when I hit EDITNOOK1. More important is to determinate between EDITOK1 and EDITOK2.

Jorge Infante Osorio
  • 2,143
  • 15
  • 26
  • first of all `live()` is deprecated now in present version of Jquery use `on() instead...And about ur problem it may be coz u are binding the event more then one time – CodeHunter Jul 23 '13 at 05:31

1 Answers1

1

I suppose that you calls $('.edit').live('click', this.clickedit); multiple times. It's the reason why this.clickedit handler will be called more as one time.

I recommend you don't use any explicit binding of this.clickedit callback. Instead of that you can use beforeSelectRow or onCellSelect. See the answer and this one for the corresponding code examples.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I start to use onCellSelect. my prob now: In 1 cell I put 3 action in this way: var actions = 'editedOK ? '
    EDITOK1  EDITOK2
    ' : '
    EDITNOOK1
    '; if actions = true I see in the same cell "EDITOK1 EDITOK2" and if actions = false I see in this cell "EDITNOOK1". How I can determinate when I hit EDITOK1 and when I hit EDITOK2
    – Jorge Infante Osorio Jul 23 '13 at 06:47
  • please see the update in my question. thanks a lot for you quick answer – Jorge Infante Osorio Jul 23 '13 at 06:53
  • 1
    @JorgeInfanteOsorio: I would recommend you better to use `beforeSelectRow` as `onCellSelect` because you can return false from `beforeSelectRow` and prevent selection of the row if the user click on some action button. Now back to your main problem currently. The element `e.target` is the DOM of clicked element (the clicked ``). Because you have multiple spans with different classes in the cell you can use `$(e.target).hasClass("edit1")` or `$(e.target).hasClass("editnook1")` to determine which span was clicked. – Oleg Jul 23 '13 at 07:02