How to initialize a custom adapter

I am creating a grid that shows multiple files by extension.

I am using a custom adapter for the grid.


I attach my code snippet below.

===========================================

<SfGrid @ref="_gridObj" TValue="MediaFile" ShowColumnMenu="true" AllowReordering="true" AllowFiltering="@Filtering" AllowPaging="true" AllowResizing="true" AllowSorting="true" Height="250px" EnableVirtualMaskRow="true" AllowExcelExport="true" AllowPdfExport="true" ContextMenuItems="@(new List<ContextMenuItemModel>() {new ContextMenuItemModel {Text = "파일 다운로드", Target = ".e-content", Id = "FileDownload"}})" Query="@Qry">

    <SfDataManager @ref="_gridObjManager" Adaptor="Adaptors.CustomAdaptor" AdaptorInstance="@typeof(BlazorBoilerplate.Shared.Models.Hyena.Project.MediaFileAdapter)">

    </SfDataManager>

    <GridEvents TValue="MediaFile" RowSelected="OnRowSelected" ContextMenuItemClicked="ContextMenuItemClickedHandler"></GridEvents> @*OnActionComplete="ActionCompletedHandler"*@

    <GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Single" EnableToggle="false" CheckboxMode="CheckboxSelectionType.ResetOnRowClick"></GridSelectionSettings>

    <GridPageSettings PageSize="@PageSize"></GridPageSettings>

    <GridColumns>


        @if (projectMediaFileType == "All")

        {

            <GridColumn Type="ColumnType.CheckBox" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" Width="51"></GridColumn>

            <GridColumn Field=@nameof(MediaFile.Id) HeaderText=" Id " HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" Visible="false" Width="100" IsPrimaryKey="true"></GridColumn>

            <GridColumn Field=@nameof(MediaFile.HitCount) HeaderText=" HitCount " HeaderTextAlign="TextAlign.Center" Width="80" Visible="@hitCount" TextAlign="TextAlign.Center">

                <Template>

                    @{

                        var pro = _projectId;

                        var storagespace = (context as MediaFile);

                        <div>

                            <span> @string.Format(CultureInfo.CurrentCulture, "{0:N0}", storagespace.HitCount)</span>

                        </div>

                    }

                </Template>

            </GridColumn>

.

.

.

 else if (projectMediaFileType == "Email")

        {

            <GridColumn Type="ColumnType.CheckBox" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" Width="51"></GridColumn>

            <GridColumn Field=@nameof(MediaFile.Id) HeaderText=" HeaderText " HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" Visible="false" Width="100" IsPrimaryKey="true"></GridColumn>

            <GridColumn Field=@nameof(MediaFile.HitCount) HeaderText=" HeaderText " HeaderTextAlign="TextAlign.Center" Width="80" Visible="@hitCount" TextAlign="TextAlign.Center">

                <Template>

                    @{

                        var storagespace = (context as MediaFile);

                        <div>

                            <span> @string.Format(CultureInfo.CurrentCulture, "{0:N0}", storagespace.HitCount)</span>

                        </div>

                    }

                </Template>

            </GridColumn>

            <GridColumn Field=@nameof(MediaFile.SentDateView) HeaderText=" SentDateView " HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center" Type="ColumnType.Date" Format="yyyy-MM-dd hh:mm:ss" Width="100"></GridColumn>

            <GridColumn Field=@nameof(MediaFile.Name) HeaderText=" Name " HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Left" Visible="false" Width="200"></GridColumn>

            <GridColumn Field=@nameof(MediaFile.SubjectView) HeaderText=" SubjectView " HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Left" Visible="true" Width="150"></GridColumn>

            <GridColumn Field=@nameof(MediaFile.FromView) HeaderText=" FromView " HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Left" Width="150"> </GridColumn>

            <GridColumn Field=@nameof(MediaFile.ToView) HeaderText=" ToView " HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Left" Width="150">

                <Template>

                    @{

                        var email = (context as MediaFile);

                        <div>

                            <span>

                                @if (email != null)

                                {

                                    var toTemp = email.ToView.Split(";");

                                    for (int i = 0; i < toTemp.Length - 1; i++)

                                    {

                                        if (toTemp[i].Length > 3)

                                        {

                                            if (i > 0)

                                            {

                                                <br />

                                            }

                                            @*<span class="fad fa-user"></span>*@

                                            @toTemp[i]

                                        }

                                    }

                                }

                            </span>

                        </div>

                    }

                </Template>

            </GridColumn>

.

.

.

@code {

    SfGrid<MediaFile> _gridObj { get; set; }

    SfDataManager _gridObjManager { get; set; }

    private List<MediaFile> GridData { get; set; }

public Query Qry { get; set; } 

    protected override async Task OnInitializedAsync()

    {

        _paramAnalysisPage.ProjectChangeEvent += RefreshGridEventHandler;

        _paramAnalysisPage.OnChangeGrid += RefreshSelectedGrid;

        _paramAnalysisPage.QueryChangeEvent += RefreshGridEventHandler;

    }

.

.

.

private async void RefreshGridEventHandler(object sender, long projectId)

    {

        if (_paramAnalysisPage.ProjectId == 0)

            return;

        projectMediaFileType = _paramAnalysisPage.ProjectMediaFileType.ToString();

        imageSize = "320";

        switch (projectMediaFileType)

        {

            case "Image":

            case "Ocr":

                imageSize = "120";

                SoundType = "이미지";

                break;

            case "Video":

                SoundType = "비디오";

                break;

            case "Audio":

            case "Stt":

                SoundType = "오디오";

                break;

        }

        int pageIndex = 0;

        string sortField = "Id";

        string sortDirection = "ASC";

        string searchQuery = _paramAnalysisPage.GetQueryAndSetUrl();

        hitCount = false;


        if (searchQuery != null && searchQuery != "")

        {

            sortField = "HitCount";

            sortDirection = "DESC";

            hitCount = true;

        }


        _pagedListRequestObj = new PagedListRequestObj

        {

            projectId = _paramAnalysisPage.ProjectId,

            ConnectionId = _connectionId,

            physicalPath = _paramAnalysisPage.QueryWorkPath,

            pageIndex = pageIndex,

            pageSize = PageSize,

            actionTag = _paramAnalysisPage.ActionTag,


            dtSearchOption = new dtSearchOption

            {

                SearchType = dtSearchTypes.Boolean,

                Stemming = false,

                PhonicSearching = false,

                FuzzySearching = false,

                Fuzziness = 3,

                DateSearching = true,

                DateSearchFrom = _paramAnalysisPage.DateSearchFrom,

                DateSearchTo = _paramAnalysisPage.DateSearchTo,

                Synopsis = false

            },

            fromDate = null, //_searchParam.StartDate,

            toDate = null, // _searchParam.EndDate,

            projectWorkSpaceIds = _paramAnalysisPage.QueryWorkIds,

            sortField = sortField,

            sortDirection = sortDirection,

            query = null,

            searchQuery = searchQuery,

            mediaFileType = _paramAnalysisPage.ProjectMediaFileType,

            timeZone = "+0900",

            FolderId = 10

        };


        Qry = new Query().AddParams("PagedListRequestObj", _pagedListRequestObj);

        await InvokeAsync(StateHasChanged);

}


===========================================

When a query is sent to the custom adapter, the grid information to be displayed in the previously displayed grid information is 'added' and sent to the controller.


Is there a way to initialize the adapter?

or Is the code I wrote wrong?


1 Reply

RN Rahul Narayanasamy Syncfusion Team November 18, 2021 03:35 AM UTC

Hi ArcBlue, 

Greetings from Syncfusion. 

We have validated your query and you can find the detail aabout how to define CustomAdaptor and know how to use the CustomAdaptor concept using below documentation link. 


Also, we are quite unclear about your requirement. Could you please share the below details. It will be helpful to validate and provide a better solution. 

  • Share more details about your exact requirement.
  • Video demonstration of the problem currently you are facing.
  • Whether did you want to change the Grid data while send Query to CustomAdaptor Read method?
  • Share a simple reproduceable sample if possible which shows your current problem.

Regards, 
Rahul 
 


Loader.
Up arrow icon