1. #1
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Vote Rating
    1
    Answers
    9
    Fire-Dragon-DoL is on a distinguished road

      0  

    Default Answered: Correct way to display a foreign key in grid column (as human readable text)

    Answered: Correct way to display a foreign key in grid column (as human readable text)


    I found some solutions but none of them satisfact me enough. I would like to hear from you which possibilities do I have to display a foreign key text in human readable format. I'll bring you an example

    Suppose I have Comment which has these fields: Id, Text, Author_Id
    Now there is Author, which has: Id, Name

    Author_Id is an int, like Id on both models. Name and Text are strings.

    Now I'm displaying a grid containing all comments, but I would like to show to the user instead of an id in Author_Id, the name of the author.

    What possibilities do I have to do this? The only way I currently found is loading all Author store (with all records) and eventully render it.

    Are there any better solution?

    Expecially, if I create a field that is used just to display this value (server side so), like Author_Id_Name, the problem is that if I edit Author_Id in my grid, Author_Id_Name won't get updated because Ext doesn't reload all record but just updates columns I edited.

    What do you suggest?

  2. I prefer to create a view using joined fields. When you update the id, the string value will follow.
    This way user can also search the string value.

    To me this much better than rendering at the client.

    Scott.

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,154
    Vote Rating
    475
    Answers
    686
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    I prefer to create a view using joined fields. When you update the id, the string value will follow.
    This way user can also search the string value.

    To me this much better than rendering at the client.

    Scott.

  4. #3
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Vote Rating
    1
    Answers
    9
    Fire-Dragon-DoL is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    I prefer to create a view using joined fields. When you update the id, the string value will follow.
    This way user can also search the string value.

    To me this much better than rendering at the client.

    Scott.
    Thanks for suggestion. When you raise your row editor, I imagine you show a selectbox to choose an id (which is integer however). Do you handle the fact that you are updating a "string" value with the int on server side?

    I consider yours a valid suggestion, if you can actually update the field.

    Still I prefer to show the user a combobox filter instead of string (but that's not a problem I can do the same).

    I'll use your technique in my next project I think.

  5. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,154
    Vote Rating
    475
    Answers
    686
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Since it is a view, you update the id only. The string (join field) is for user display/search only.

    Scott.

  6. #5
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Vote Rating
    1
    Answers
    9
    Fire-Dragon-DoL is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    Since it is a view, you update the id only. The string (join field) is for user display/search only.

    Scott.
    How do you implement it? I mean, do you have 2 fields on your model, one is author_id and the other is author_id_to_string, and you update only author_id and author_id_to_string gets autoupdated?

  7. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,154
    Vote Rating
    475
    Answers
    686
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Correct .. you add the new field to model.

    Scott.

  8. #7
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Vote Rating
    1
    Answers
    9
    Fire-Dragon-DoL is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    Correct .. you add the new field to model.

    Scott.
    Mhhh... that's how I did it before, however when I update the id field, the string field for some reason doesn't get updated (I have to refresh the store), I think because Ext updates the id field but doesn't read the whole object from the server again, so the string doesn't get updated. I need a way to force the "string field" update too.

  9. #8
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,154
    Vote Rating
    475
    Answers
    686
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Were you using a SQL view at the server side as the table used to populate store?

    model has:
    id_product
    product_name // join field

    CREATE VIEW viewInvoices (
    SELECT id_product, products.product_name AS product_name
    FROM invoices
    JOIN products ...
    )

    Updating the id will automatically update name.. same of you use SELECT * viewInvoices

    Scott.

  10. #9
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Vote Rating
    1
    Answers
    9
    Fire-Dragon-DoL is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    Were you using a SQL view at the server side as the table used to populate store?

    model has:
    id_product
    product_name // join field

    CREATE VIEW viewInvoices (
    SELECT id_product, products.product_name AS product_name
    FROM invoices
    JOIN products ...
    )

    Updating the id will automatically update name.. same of you use SELECT * viewInvoices

    Scott.
    Ah thanks, I were missing the SQL View!
    I'll look for a different solution at the moment however, because I'm using sqlite so I don't have views support :\

Thread Participants: 1

Tags for this Thread