0

I'm trying to use jQuery UI Autocomplete inside a jqGrid in the dataInit. I'm doing it like this:

{ name:'ac_fin_g', index:'ac_fin_g', width:75, editable: true, edittype: 'text',
    editoptions: {
        dataInit: function (elem) {
            $(elem).autocomplete({
                source: 'autocomplete.php',
                select: function (event, ui) {
                    #('ac_fin_g').val(ui.item.value);
                }
            });
        }
   }}

And in the function ondblClickRow I'm passing select like a parameter:

ondblClickRow: function (id, select) {
    if (id) {
        if (id !== lastSel) {
            $('#list').restoreRow (lastSel);
            $('#list').editRow (id, true, select);
            lastSel = id;
        } else {
            $('#list').restoreRow (lastSel);
            lastSel = "";
        }
    }
}

This is working but just for the first row.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
mailazs
  • 341
  • 6
  • 22

1 Answers1

1

I think that the main reason of your problem is wrong usage of ondblClickRow callback. The second parameter of ondblClickRow callback is the index of the row in the grid. There are other option which you can use. The most full prototype of ondblClickRow callback contains 4 parameters:

// one can use ondblClickRow: function (id) { below because iRow, iCol, e are not used
ondblClickRow: function (id, iRow, iCol, e) {
    var $self = $(this);
    if (id !== lastSel) {
        $self.jqGrid("restoreRow", lastSel);
        lastSel = id;
    }
    $self.jqGrid("editRow", id, true);
}

The third parameter of editRow is oneditfunc callback. The usage of iRow number as oneditfunc callback is wrong.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks for reply @Oleg! I'm sorry but I didn't understand what you mean :( – mailazs Mar 15 '13 at 20:11
  • 1
    @mzs_newbie: `ondblClickRow` is callback function. All parameters of the functions are defined by jqGrid and you can't change it. You used `ondblClickRow: function (id, select) { ... $('#list').editRow (id, true, select); ...}` in your code. So you forward 2-nd parameter of `ondblClickRow` (which you name as `select` and which I named `iRow`) as 3-d parameter during calling of `editRow`. It's wrong. – Oleg Mar 15 '13 at 20:18
  • Ohhh ok. I understood now. Thanks. I changed everything but it's still not working. – mailazs Mar 15 '13 at 20:23
  • @mzs_newbie: What is not working now? Do you removed `$('#list').restoreRow (lastSel);` from the `else` part see `ondblClickRow`? I am not sure also that `select` callback of `autocomplete` is required. – Oleg Mar 15 '13 at 20:26
  • Now it's still the same that before... The edit and autocomplete just work for the first row. Yes, I changed everything you said, and I also removed select. – mailazs Mar 15 '13 at 20:30
  • @mzs_newbie: Could you include the data which returns `'autocomplete.php'`? – Oleg Mar 16 '13 at 07:02
  • of course! :D I'm sorry the delay but I just could reply you today. The 'autocomplete.php' has: `SQL`: `$SQL = "SELECT DISTINCT ac_fin_g FROM circ_69 WHERE ac_fin_g ILIKE '%".$term."%'"; $result = pg_query( $con, $SQL ) or die ("Couldn't execute query." . pg_last_error())` And now the part of the return: `$i=0; while($row = pg_fetch_array($result)) { $response[] = row[ac_fin_g]; $i++; } echo json_encode($response); ` – mailazs Mar 18 '13 at 11:59
  • @mzs_newbie: Could you post example of **the data** not the code. In the case I could save the server response in the file and I would try to reproduce the problem without having your server. – Oleg Mar 18 '13 at 12:02
  • Humm ok, I'm sorry. For example, if I write `"U"` it returns me: `["ILUMIN ","ROTA FUGA "]`. The way that I'm returning the data is wrong? – mailazs Mar 18 '13 at 12:06
  • 1
    @mzs_newbie: Try with [the demo](http://www.ok-soft-gmbh.com/jqGrid/mzs_newbie.htm). It's almost what you posted. I don't see any problems. By the way the code `#('ac_fin_g').val(ui.item.value);` which you posted means sure `$('#ac_fin_g').val(ui.item.value);`. Look at the code of the demo. I used `dataInit: function (elem) {var $elem = $(elem);$elem.autocomplete({source: 'autocomplete.php', select: function (event, ui) { $elem.val(ui.item.value); }});}` – Oleg Mar 18 '13 at 14:20
  • Thank you so much! I tried but it's still not working. I think is something that I'm missing... I will try to fix this and later I let you know about it! But once again thanks for you time and your help! :) You are always helpful! – mailazs Mar 18 '13 at 14:31
  • @mzs_newbie: You are welcome! Do you have the demo with the bug online available? In the case I could just look at full demo. Probably the reason is very easy, but you just don't post the information which is the real origin of the problem. If you can provide live demo, please use non-minimized version (`jquery.jqGrid.src.js`) of jqGrid in the demo and post me just the link (URL) to the demo. – Oleg Mar 18 '13 at 14:40
  • Unfortunately, I don't have :( But I can put in some site that provides a temporary hosting file and maybe you can look from there? I had another version of the code, and I tried to change it and now it's working, but I don't know what's wrong with the other version. – mailazs Mar 18 '13 at 14:53
  • 1
    @mzs_newbie: Do you verified that you filled `id` of rows correctly in the demo which doesn't work? Probably you have some id duplicates in the demo? – Oleg Mar 18 '13 at 14:58
  • Thank you so much! I found it! In the response of my php.php file (that is the file that I fill the grid) I wasn't returning the `id` so I didn't have something to identify the row. Thanks for all and I'm sorry for the newbie questions!!! :) – mailazs Mar 18 '13 at 15:14
  • @mzs_newbie: You are welcome! I'm glad that I could help you. – Oleg Mar 18 '13 at 15:22