Unable to assign list to data grid

I know this is my mistake, but I’m not able to see what I’m doing wrong.

I create an empty list
image

then populate it this way

so I have a list of items each with a name and value field

the data grid columns are defined
image

here is the dg data row

image

unfortunately my dg displays "no rows to show "

I added a print statement for the list

so it looks like it is a list with 5 items each with a name and value field. Can you show me what I’ve messed up?

Thanks
H

You are modifying a list while iterating over the same list. What are you trying to do here?

mind_id_field_list is a list of properties (mine_id, mine name, and 3 others )

mind_id_field_list_dg is the list I need to populate that will be used to fill the data row logic

the selectedmine and all of its data has been pulled into "selected_mine_id_data " but there are 30 items here and I want to put only the five listed in “mind_id_field_list” into my data grid

two columes Name and Value

so for each item in mind_id_field_list i add an item to the list with Name=‘j’ and Value= get property “j” of selected_mine_id_data

basically my database table has 30 columns. I’m going to break those into 5 data grids (by attribute group. )

I hope this gives a better understanding of what I’m trying to accomplish

Thanks,
H

Hello @hharrington

If I understood you correctly, you want to take the first 5 items from selected_mine_id_data (in my example, data) and put them in mind_id_field_list_dg (in my example, it is list_dg) by name of the property from mind_id_field_list (in my example, it is list).
My example:


Output:

Please let me know if I understood you correctly and this is what you were looking for.

Regards,
Vladimir

Thanks for taking a look at this.

when a user selects a mine, I run a query against the mine_data table and load all 30 fields (columns ) into a variable like so stored in variable “selected_mine_id_data”

The 5 fields I want to load into this data grid are in a comma separated list stored as "

so my loop to build the datagrid list only needs one for loop

so a walk though the list of columns (mind_is_field_list) so a create an object with name set to the jth item in mind_is_field_list then I set the value to be selected_mine_id_data[j]
then I add this to list mind_id_field_list_dg

when I print out mind_id_field_list_dg

it looks to me like its got what I need an array of 5 elements each with a name and value

but when I set the rows data logic to “get property” ‘mind_id_field_list_dg’ of pagedata

the data grid shows now rows to display. I can’t figure out why.

thanks again.
H

here is a datagrid list that works

vs the one that does not

The one that works has an extra line in the output which is missing from the failed one. I’m not sure if this difference is significant

H

and here in the data grid row logic

if I take “mind_id_field_list_dg” and place each object in a new list and set the data logic return to the new list everything works.

I do not understand what this is changing to make it work.

H

I am trying to wrap my head around the logic and am still confused about the data manipulations you’re using. What I understood so far is:

  1. You load data from the database, each record has 30 columns
  2. You narrow down each object to have only 5 columns
  3. Then you need to display the trimmed objects in a data grid.

Did I get this right?

If so, my question is why don’t you initially retrieve the data from the database to have only the specified columns? Why load all of them?

Regards,
Mark

I have a database table (mine_data ) which has 30 columns. mine_id is a unique ( 1 of the 30 columns )

user choses a mine_id on which to see all the mine details (all 30 columns of data)

so I pull all the mine info into variable and I know only one row will be returned because mine_id is unique.

as all the mine information (columns ) fall into 5 groups. to keep it simple 5 groups * (5 or 6 entires per group ) . I plan to use 5 data grids to show each of these groups.

so I created a list of the first 5 columns “mind_id_field_list”
I created an empty list “mind_id_field_list_dg” to hold the list of Name,Value (s) where Name will be the column name and Value will be the value of mine_id → column

here is an example

image

as you can see the “name” column here are the mine_data columns and the value is the mine_id (see first row ) on the mine_data for that mine for “Name” column.

Let me know if you have any questions.
also, thanks again for your (all of you) time.
H

Hello @hharrington

Why don’t you specify the necessary properties right away? You can also exclude unnecessary properties.
https://backendless.com/docs/rest/data_working_wih_properties.html

Regards,
Inna

I’ve got 30 columns (fields) per row.

I want to display all 30, but not in one data grid. My thought on this is assigning all 30 all at once into a variable then parsing the variable to pull out each group of fields means I only access the database once, then populating each data grid is a local operation.

H

Both Data Grid and Data Table components work with the assumption that every row is a separate object. You’re trying to render a single object over 5 rows. I think this causes the misunderstanding and the technical challenge. While it is possible what you’re trying to do, I honestly believe you would be better off creating a Block or Container-based element that uses Text components to bind to the appropriate columns/fields in the object you’re working with. This would be a tremendous simplification of your app without losing any functionality. Have you given any thought to that approach?

I did think about using input blocks, and then using the binding logic to deal with content. But I’d have to make 30 of them with 30 different bindings which is a lot of properties to set.

my thought was: create a list of related fields(columns) then create a new list of objects with the column name as the first field (Name) and value as the mine_id/column name.

I don’t think this is a single object over 5 rows but a list of objects with two fields populated the name of a column and the value in the database row of mine_id (row) and column.

H

It is one of the approaches and not the worst of them. It has one big advantage – it is highly extensible (to any number of fields), if really need it.
Another approach is to create a custom component with the custom logic and rendering, but it may be not trivial.
By the way, did you try to work with JSON as a type of a field - it can contain a complex object/array?

The issue I am seeing when I build my list using a property “datagridtestlist” of page data and then set the datagrid row logic to be that property

image

the data grid is blank
image

but when I create the list as a variable then store the variable in a property of page data

I get this
image

the only difference between these data grids is the first one gets the property from page data. while the second one the list is created in a var and then saved to a property.

I created a test page to show the issue.
app id 9359F741-6D5D-AEF2-FF22-4834A2050400
container : default_test_9_21_23
page name: data_grid_test_page

to use, load the page. Then click on any of the 4 entries in the top data grid.

the first data grid shows nothing while the second one works as expected.

but then I print out the contents they look identical

H

I created a copy of that page and made a minor change in the “on cell clicked” event.

One of the most significant issues I see in your logic (and it is everywhere) is that you do not use variables at all for any intermediate values you’re storing. Instead, you store everything in Page Data. This is highly inefficient because every time you put anything into Page Data, it forces the re-rending of the entire page. Additionally, it causes the problem you’re seeing, specifically, you put an empty list into Page Data and then you modify it, however, that does not trigger re-render, as a result, the data grid is never refreshed with the new data.

Regards,
Mark

your saying if a property in pagedata is set to an empty list, that when it is updated (so it is no longer empty) it is never re-rendered? I think this is the first time initializing a variable (I guess technically its a property not a variable) before using it actually caused an error.

H

If you update a list inside of PageData, the PageData itself does not see any changes, as a result, there is no re-render event.

I am not sure what error you’re referring to. Did you see the page with my changes? It is called marktest, there are no errors on that one and all data grids are being populated with data.

Ok so if a property is stored in page data as an empty list and then that property is updated it will not rerender so the change will not be seen.

so I added a new datagrid and tried this

image

so here I am setting property datagridtestlist2 to an empty list.
then I update it.

if changing the empty list so it has data does not cause a rerender I would expect the data grid using it to be blank but its not. It shows the data.

for example
here I start with a property set to empty list. then I add to the list. but it should not cause a rerender so I should not see the data grid update. but I do.

while this starts with an empty list and I add to the list but I don’t see the changes.

so whats the difference? in both I start with an empty list. In both I add items to the list. but in one I see the data in the data grid but in the second I don’t see the data.

I feel like there is a fundamental concept I’m missing.

H

What you are doing below is updating the same Page Data property three different times with three different values:

In the logic below you assign an empty list to a property in Page Data. That causes a re-render event. After that you modify the list. Yes, the list will be updated, however, the UI will not know that it got updated because PageData was not modified (only its contents did):

Again, please take a look at the changes I made in the marktest page, it is a replica of your page, but with the changes that got it working.

Regards,
Mark