0

I have a grid using jqGrid and in this grid I have the rows editable with inline editing. I'm trying to do autocomplete in the rows that is editable. Is this possible to do? And in case of yes, how can I identify these rows?

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

1 Answers1

0

You could set the classes: autoCompleteFieldClassName in the colModel of the column, and then use that to add in your auto complete fields on edit.

Example: in the colModel you can assign a class to the column cells via the option classes: autoCompleteFieldClassName

This class would then allow you to set a jQuery selector on the inline edit event which would allow you to select the input element attached to this cell column. Once you have this element you can attach an jQuery autocomplete

$(inputElement).autocomplete({ source: '/Controller/GetAutocompleteInformation',
    minLength: 2, autosearch: true,
    select: function (event, ui) {
        $(elem).val(ui.item.value);
Mark
  • 3,123
  • 4
  • 20
  • 31
  • Thanks for reply one more time @Mark! I'm sorry but could you give me an example? I didn't understand how I can implement this. – mailazs Mar 08 '13 at 17:34
  • See the edit...Firebug or one of it's equivalents will be your friend as you look to find the elements in your grid to build up this functionality. – Mark Mar 08 '13 at 18:16
  • Hummm ok, now I got it! Thanks again @Mark :) – mailazs Mar 08 '13 at 18:28
  • Hi again @Mark... I need your help again :) I tried to do that but this is not working... when a try to write a letter in the field, the processing almost stop and then he take the wrong value, he get the value that was in the grid :/ I don't know how to fix it, if you could help me! – mailazs Mar 08 '13 at 19:28
  • I'm sorry let me rewrite this... When I try to enter one or more letters in the field (that hipotetically has the autocomplete), the autocomplete don't work and the page(html) stops to respond... I can't do anything more in the page because I don't get this! And when I look at firebug... the `term`has the wrong value... it has the value that was in the grid and not the value that I wrote. – mailazs Mar 08 '13 at 19:37
  • Is your autocomplete being successfully attached to the correct input element? – Mark Mar 08 '13 at 19:58
  • I think so... A part of my code is: `function autocomplete_element (value, options) { var $ac = $(''); $ac.val(value); $ac.autocomplete ({ source: function(request, response) { $.getJSON("autocomplete.php", { term: request.term }, response); } }); return $ac; } |another function| function autocomplete_value(elem, op, value) { if (op == "set") { $(elem).val(value); } return $(elem).val(); } ` – mailazs Mar 08 '13 at 20:11
  • Well test that you can set up a regular text input box, attach the autocomplete and have it work as expected and then it should be same if you are selected the correct element with your jQuery selector based on the class you set on the colModel. Remember it is not going to be the class name for your selector but rather the child element that gets attached with the inline edit. – Mark Mar 08 '13 at 20:14
  • Hi again @Mark... I have a doubt... Please, how am I sure that the values that I get from database is going to the field of the grid correctly? – mailazs Mar 11 '13 at 12:13
  • For the autocomplete? Examine the json you get from the server? This seems like basic troubleshooting. – Mark Mar 11 '13 at 13:06
  • Yes, for the autocomplete. Because the response that I get from the server is something like `row=Array{"rows":[{"index":null,"cell":"LIGHT"}]}`. I'm sorry for the newbie doubt but this is not in JSON format, is this? PS: This what I printed is the echo of json_encode – mailazs Mar 11 '13 at 13:10
  • Looks close to me... I"m not exactly sure what you are copying but you can try google for JSON parsersers/checkers. You should be able to run a query against your db and see if autocomplete is returning the valid results. – Mark Mar 11 '13 at 13:25
  • I verified in the json validator and the JSON is ok. But my problem is that the "input" of autocomplete doesn't show anything. When I write something in the field it does the autocomplete, but don't show in the "input" the options that I have through the word that I wrote. Is this so confused or did you understand me? – mailazs Mar 11 '13 at 13:31
  • Ohh I found what I was doing wrong... I had put a print_r in my code and because of this my grid was not working... now the "autocomplete" is showing but just a small box... I don't know how to fix this, but if I fix I will post here! – mailazs Mar 11 '13 at 13:59
  • My problem was the return of JSON. [Link](http://stackoverflow.com/questions/15384918/json-returning-json-to-a-input-jqgrid-autocomplete) to the question that solve this :) – mailazs Mar 18 '13 at 12:16