New-UDDataGrid showing no data when $data is only one row table

Product: PowerShell Universal
Version: 4.2.12

Hello i have strange problems with New-UDDataGrid . It will be hard to explain because it behaves so differently depending on different conditions.

So im using New-UDUpload to upload some csv - then i import it as csv to variable.
this variable is then loaded as data to New-UDDataGrid
And everything is fine as long as I use Out-UDDataGridData and column format as:

 @{ field = "firstName"; editable = $true; DisableColumnMenu = $true;Width = 100  }
 @{ field = "lastName" ; editable = $true; DisableColumnMenu = $true;Width = 100 }

But this method as far as i understand do not allow to use -Render switch , which i want to use so i used this method to define columns.

New-UDDataGridColumn -Field 'firstName' -Align left -Editable -DisableColumnMenu -Width 100  -Render {
some code
}

And now is where it gets strange :slight_smile:

When I change to New-UDDataGridColumn and leave Out-UDDataGridData everything works expect i got such errors:
image

When i remove Out-UDDataGridData and add this construct:

 @{
   rows = $Data 
   rowCount = $Data.Length
}

Everything works expect situation when uploaded file has only one row (its not displayed at all)

There are also some different behaviors with OnEdit block. With first method everything works as expected (but no render) but with other method i have some different reading on $EventData.newRow and $EventData.oldRow variable. But lets first fix those issues that i described above , maybe this error will be gone.

Ps. when data is constructed as in docs

$Data = @(

         @{ Name = 'Adam'; Number = Get-Random}

         @{ Name = 'Tom'; Number = Get-Random}

         @{ Name = 'Sarah'; Number = Get-Random}

     )

and not imported form csv - no such errors as far as i tested

more update
obviously you can use render parameter in such code:

@{ Name = 'Adam'; Number = Get-Random}

and i almost made it work.

It work for the most of the times but sometimes gives strange errors or not doing what it supposed to do.
so my next question is (maybe im doing it in w wrong way):
how should I update data in uddatagrid ?

Because:

  1. onedit block returns only new row and old row arrays
  2. onselection block returns only selected rows number.

I wrote some code to serach for the old row or selected row in input array and delete or update this row
It was not easy (at least at first ) since data in input array could be not unique
I had to add id column and force populate it to uddatagrid so I can compare uddatagrid id with input array id
Then I sync element with uddatagrid.

And as I said it works for most of the times but if you do more updates / deletion at once especially with renderer rows or delete previously edited rows it can trow an error/duplicate row/ or do nothing at all.

Probably i can make it better but im working on it for few days now and im kind o tired of this approach.

So i thought that why update input array every deletion/ change ? I will make save button and all chages will be applied then.
Sounds good but also do not work - i cant see a way (easy way) to read all changes that I have made to uddatagrid and then populate it to input array and sync element.

So dear friends. Could someone share with me a working example of uddatagrid code with editing and deleting functionality ?

All examples in the docs are just simply displaying values of what you have edited ot selected but as wee can see in real world such scenarios are not very common.

Probably i don’t not understand fully how it behaves and it is simpler way to achieve it but im kind of stuck right now…

PS. nightly build 4.2.13 seems to resolve most if not all those problems.