We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Example of custom edit dialog with sfDataManager and Adaptor="Adaptors.UrlAdaptor"

Hello,

i create a hosted Blazor Wasm with VS2022 and Net 6.x.

On the Client i use SfGrid (Version 20.2.0.36) with TValue and sfDataManager and the

<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog">

All is running ok. 

But when i try to customize the edit dialog with 'template' i got some errors.

Do you have samples that use remote data via  sfDataManager and Adaptors.UrlAdaptor?

All samples i found use local data and a propertie called 'DataSource' that i don't use.

Thanks

Patric



8 Replies 1 reply marked as answer

SP Sarveswaran Palani Syncfusion Team October 15, 2022 03:44 AM UTC

Hi Patric,

Greetings from Syncfusion support.

We are currently Validating the reported query at our end, and we will update the further details within two business days. Until then we appreciate your patience.

Regards,

Sarveswaran PK



SP Sarveswaran Palani Syncfusion Team October 20, 2022 01:06 AM UTC

Hi Patric,


Sorry for the delay.


We have analyzed your query and prepared Adaptors.UrlAdaptor sample for handling CRUD operation in the oldest version sample. We have facing some complexities while converting into latest version. We’ll prepare and update the latest version sample within two business days.


Until then we appreciate your patience


Regards,

Sarveswaran PK


Attachment: UrlAdaptor1_d82db3ad.zip


PG Patric Gehl October 20, 2022 08:31 AM UTC

Hi Sarveswaran,

thanks for your suport. I take a look in your old sample and wait for your new one. 

This is my first Blazor Wasm with .Net 6 and VS2022 and i think there are some bugs in the whole environement. Especaly scaffolding makes big trouble (crashes with useless error mesages). And the joke, if i do the same thing with .Net 5 and VS 2019 it simply works perfect.


Again thanks for your support


Patric



SP Sarveswaran Palani Syncfusion Team October 26, 2022 05:47 PM UTC

Hi Patric,


Sorry for the delay and inconvenience caused.


We’re facing some complexities while preparing a sample. Kindly share the what kind of issue you’re facing while making scaffolding sample, share issue reproducible sample to us and video demo of an issue to us. It’ll be more helpful for us to validate the query and provide the solution as early as possible.


Regards,

Sarveswaran PK





PG Patric Gehl replied to Sarveswaran Palani October 27, 2022 08:41 AM UTC

Hi Sarveswaran,

the example from your last post was not very useful. I create the datagrid and the contoler via Syncfusion Scaffolding as described in this document (https://help.syncfusion.com/extension/blazor-extension/visual-studio/scaffolding).

This tool is very helpful!! But it generat the following structure:

<SfGrid ID="Grid" TValue="TZeittät" Height="100%" AllowSorting="true" AllowGrouping="true" AllowPaging="true" Toolbar="@(new List<string>() { "Search", "Add", "Edit","Update","Delete","Cancel" })" AllowFiltering="true" AllowSelection="true" ShowColumnMenu="true">

  <SfDataManager Url="/api/TZeit_DataGrid" InsertUrl="/api/TZeit_DataGrid/Insert" UpdateUrl="/api/TZeit_DataGrid/UpdateTZeittät" RemoveUrl="/api/TZeit_DataGrid/DeleteTZeittät" Adaptor="Adaptors.UrlAdaptor" ></SfDataManager>


I think that TValue is like the Datasource; so with this code i can fix this problem:

<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog">

<Template>

@{var Zeit = (context as TZeittät);

<div>

<div class="form-row">

  <div class="form-group col-md-6">

  <label class="e-float-text e-label-top">Aktivitäts-ID</label>

  <SfNumericTextBox ID="OrderID" @bind-Value="@(Zeit.ZeiterfRefnr)"      Enabled="@((Zeit.ZeiterfRefnr == null) ? true : false)"></SfNumericTextBox>

</div>

<div class="form-group col-md-6">

 <label class="e-float-text e-label-top">Datum </label>

  <SfDatePicker ID="Datum" @bind-Value="@(Zeit.Datum)"></SfDatePicker>

</div>

</div>  ...


But i get an error that ' context' from   (context as TZeittät) is not available! But if i run the app, it works and i don't know why.

So can you explain this??


And i found an other problem with the generated controler. It create the DBSet like:

    public class TZeit_DataGridController : ControllerBase

        {

        private readonly MyAdminoContext db;

        public TZeit_DataGridController(MyAdminoContext context)

        {

            db = context;

        }

       public DbSet<TZeittät> GetAllTZeittät()

      {

       try

      {

      return db.TZeittät;

      }

     catch

    {

      throw;

    }

   }

that is later used in:

        // POST api/<controller>

        [HttpPost]

        [Route("api/[controller]")]

        public Object Post([FromBody]DataManagerRequest dm)

        {

            IEnumerable DataSource = GetAllTZeittät().ToList();

....

My question: Where is the best place to inject a static 'where-condition' in the DBSet?

As far as i understand, if the statement  ' DataSource = GetAllTZeittät() ...' is executed, the call to the database is executed and collect the whole table!

But if i place a where condition in the DBSet like '

return db.TZeittät.Where(x => x.Mandantrefnr == 123);' the result can not cast in a DBSet.Entity!


Any idea how to fix this??


Thanks Patric







SP Sarveswaran Palani Syncfusion Team November 1, 2022 04:56 AM UTC

Hi Patric,

Greetings from Syncfusion support.

We are currently Validating the reported query at our end, and we will update the further details within two business days. Until then we appreciate your patience.

Regards,

Sarveswaran PK



SP Sarveswaran Palani Syncfusion Team November 3, 2022 05:28 PM UTC

Hi Patric,


Sorry for the delay,


Based on your update, We suspect that, you want to initially filter the DD. For Grid, to apply the initial filtering, set the filter Predicate object in Columns property of GridFilterSettings component. For, we suggest you to get values using ToList method in the Where condition. Kindly refer the attached code snippet and documentation for your reference.


Reference: https://blazor.syncfusion.com/documentation/datagrid/filtering#initial-filter


 

  return db.TZeittät.Where(x => x.Mandantrefnr == 123).ToList();


Regards,

Sarvesh



PG Patric Gehl replied to Sarveswaran Palani November 3, 2022 06:45 PM UTC

Hi Sarvesh,

thanks for your reply; i found a similar solution.


I think it is necessary to identify the 3 parts of my solution and where the action happens.


First: If i 'reverse engineer' the tables of my database with EF Power Tools, the entyties are stored in the .server project but to use them in the client, i moved them to the .shared project (with the change of the namespaces).


Next i create the Controller  in the .server project based on your sample with this fragment:


using Admino_Client.Shared.Models;

using Admino_Client.Server.Data;

using Admino_Client.Server.Models;

using Syncfusion.Blazor.Data;

using Microsoft.Extensions.Hosting;


namespace Admino_Client.Server.Controllers

{

    public class TMandanten_DataGridController : ControllerBase

    {

        private readonly MyAdminoContext db;

        public TMandanten_DataGridController(MyAdminoContext context)

        {

           db = context;

        }

        public List<TMandanten> GetMandantTMandanten()

        {

            try


            {

                #pragma warning disable CS8629 // Ein Werttyp, der NULL zulässt, kann NULL sein.

                var data = from tz in db.TMandanten orderby tz.MandRefnr descending where ((tz.aktiv == true) && ((tz.ErfassungsUser == sPerson) || (tz.AktualisierungsUser == "Test"))) select tz;

                #pragma warning disable CS8629 // Ein Werttyp, der NULL zulässt, kann NULL sein.

                List<TMandanten> l = data.ToList();

                return l;

            }

            catch

            {

                throw;

            }

        }

       // POST api/<controller>

        [HttpPost]

        [Route("api/[controller]")]

        public Object Post([FromBody]DataManagerRequest dm)

        {

            IEnumerable DataSource = GetMandantTMandanten();

            if (dm.Search != null && dm.Search.Count > 0)

            {

                DataSource = DataOperations.PerformSearching(DataSource, dm.Search); //Search

            }

            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting

            {

                DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);

            }

            if (dm.Where != null && dm.Where.Count > 0) //Filtering

            {

                DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);

            }

            int count = DataSource.Cast<TMandanten>().Count();

            if (dm.Skip != 0)

            {

                DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); //Paging

            }

            if (dm.Take != 0)

            {

                DataSource = DataOperations.PerformTake(DataSource, dm.Take);

            }

           return dm.RequiresCounts ? new { result = DataSource, count = count } : DataSource as object;

        }

.....}


Then in the razor page, i use

  <SfDataManager Url="/api/TMandanten_DataGrid" InsertUrl="/api/TMandanten_DataGrid/Insert" UpdateUrl="/api/TMandanten_DataGrid/UpdateTMandanten" RemoveUrl="/api/TMandanten_DataGrid/DeleteTMandanten" Adaptor="Adaptors.UrlAdaptor" ></SfDataManager>


In addition i upgraded to SF Version 20.3.0.52 and the problems with the grid editing dialog are gone in part.

The two way databindig with the sfCheckbox is a bit tricky (it is allways @bind-Value="@(...)" but the checkbox work with Checked="@(...)"!!!!). 

But i see a light at the end of the tunnel!! Since all kind of scaffolding mostly produce errors in my environment, i create the code for the grid with SQL-Statements like


  SELECT '<GridColumn Field="' + c.Name + '" HeaderText="' + c.Name + case when c.is_identity = 1 then '" IsPrimaryKey="true" IsIdentity="true" Visible="false"></GridColumn>'

  else case when ty.Name like 'date%' then '" Type="ColumnType.DateTime" Format="d" AutoFit="true"></GridColumn>'

  when ty.Name like '%char%' then '" Type="ColumnType.String" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>'

  when ty.Name like '%int%' then '" Type="ColumnType.Number"></GridColumn>'

  when ty.Name = 'bit' then '" Type="ColumnType.Boolean" DisplayAsCheckBox="true"></GridColumn>'

  when ty.Name = 'float' then '" Format="C2" TextAlign="TextAlign.Right"></GridColumn>' end end,

COL_Bez = c.Name, Col_Nr = c.column_id, Col_Ident = c.is_identity, TypeName = ty.Name,     MaxLength = c.max_length 

FROM

    sys.columns c

INNER JOIN

    sys.tables t ON t.object_id = c.object_id

INNER JOIN

    sys.types ty ON c.user_type_id = ty.user_type_id

where t.name = 'TMandanten';


Looks a little bit weird, but it do the job especially if the table has hundreds of columns.

Again, thanks for your support,


Patric  



Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon