General Category > Help for ParamQuery Pro

autocomplete to link foreign key field


My grid has a foreign key link to the user table.  I would like to use autocomplete to search the user table for users by name but store only the user_id in the database.

Everything is working except I don't know how to store the user Id field in the grid.

( ) is the correct user_id value

How do I write it to the dataIndx:"user_id"?

I would also like to hear suggestions of how to not write the user_descriptor field to the database on save.

Bonus points:
.focus(function () {
throws an error message, but everything works when its commented out.  Any ideas what it does and if I need it?


  {title:"User ID",  width:4, dataType:"integer", dataIndx:"user_id", hidden:true},
  {title:"User", width:100, dataType:"string", dataIndx:"user_descriptor", editor: { type: autoCompleteEditor }},

var autoCompleteEditor = function (ui) {
    var $cell = ui.$cell,
        rowData = ui.rowData,
        dataIndx = ui.dataIndx,
        width = ui.column.width,
        cls = ui.cls;
    var dc = $.trim(rowData[dataIndx]);
    var $inp = $("<input type='text' name='" + dataIndx + "' class='" + cls + " pq-ac-editor' />")
        .width(width - 6)

        source: function( request, response) {
                    $.getJSON($SCRIPT_ROOT +'/fkey_search', { table:'users', srch: request.term }, function( data ) {
                        response( data )
        minLength: 2,
        select: function( event, ui ) {
            // this is where I would like to set the id value
            // alert(( ));
    }).focus(function () {
        //open the autocomplete upon focus
        // Paramvir - this gives me an error message

def fkeySearch():
  tbl = request.args.get('table', 0, type=str)
  srch = request.args.get('srch', 0, type=str)
  fmt_srch = "%"+ srch +"%"

  if tbl == 'users':
    sql = "select user_id as id, name as value from users where name ilike %s"
  r = query_db(sql, (fmt_srch,))
  json_output = json.dumps(r)
  return json_output   

[ Only Pro members may read this post. ]

rowData["user_id"] =;
updates the cell but doesn't mark the cell as dirty.

Is there a way to mark the cell as dirty the same time I write to it?

The attachment shows the error message I get from: $(this).data("autocomplete").search($(this).val());


[ Only Pro members may read this post. ]



[0] Message Index

Go to full version