Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #104651
    Peter
    Participant

    Hi,

    I have been looking at the DataBind docs but I can’t find how to bind an array of objects to a field in the grid.
    The scenario is pretty simple really – I have a column in which I would like the user to be able to pick (typing with autocomplete/filtering preferred) from a set of accounts. These accounts exist in an array of objects.
    I know how to bind an array of simple data types like strings, but not how to do the same with objects.
    E.g. an account in the array could look like this:

    {
       "No": "account-number",
       "Name": "account-name",
       "Blocked": false,
       "Type": "account-type",
       ...
       ...
       ...
    }

    Question 1: How would I bind this array to my account column by the account.No attribute, without having to build a new array containing only the account numbers?

    Question 2: Would it be possible to look in both the account.Number and the account.Name when trying to perform autocomplete/filtering from the users input?

    • This topic was modified 1 year, 7 months ago by Peter.
    #104657
    ivanpeevski
    Participant

    Hi Peter,

     

    1) You can use the getCellValue property of the column to set a function, which will return only the value of the property you wish to display.

    Here is a simple example – codepen

     

    2) One way to implement is to set getCellValue to return a string containing both properties. So if account number is “15” and name is “John”, return “15, John”. Then set the ‘template’ of the column to display only one of the values. In this way, filtering will work for both values

     

    Best Regards,
    Ivan Peevski

    Smart UI Team
    https://www.htmlelements.com/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.