DSTemplate_UI 1.0.5.1

dotnet add package DSTemplate_UI --version 1.0.5.1
                    
NuGet\Install-Package DSTemplate_UI -Version 1.0.5.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DSTemplate_UI" Version="1.0.5.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DSTemplate_UI" Version="1.0.5.1" />
                    
Directory.Packages.props
<PackageReference Include="DSTemplate_UI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DSTemplate_UI --version 1.0.5.1
                    
#r "nuget: DSTemplate_UI, 1.0.5.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DSTemplate_UI@1.0.5.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DSTemplate_UI&version=1.0.5.1
                    
Install as a Cake Addin
#tool nuget:?package=DSTemplate_UI&version=1.0.5.1
                    
Install as a Cake Tool

DSTemplate_UI

a fast and easy way to make tables in your razor pages

Quick Start Guide

as the razor pages mechanic work, you need to copy 2 default .cshtml files to your Views directory. consider downloading them from the repository.

do this steps to create a table:

  1. use the IDSTableController interface to implement your controller: and implement the two functions DSGetTableData and DSGetTableDataCount
public class ModelController : IDSTableController{
    public async Task<JsonResult> DSGetTableData(string tableName, string sortPropertyName, bool? sortDesending, string filters, int page = 1, int rowsPerPage = 10, string routeValues = null)
{
    if (tableName == "custom-table")
    {
        var query = _repository.Query; //must be an IQueryable<Model>
        //get the route values you set in the tag helper
        var routeValuesParsed = JsonConvert.DeserializeObject<List<KeyValuePair<string, object>>>(routeValues);
        var userId = (string?)routeValuesParsed?.Where(x=>x.Key == "userId").FirstOrDefault().Value;
        if (userId == null)
        {
            return Json("user most not be null!");
        }
        //add any filters you want to the queryable
        query = query.Where(g=>g.UserId == new Guid(userId));

        //You MUST use the DoSFP (do sorting filtering and pagination) at the end of any changes to the query
        query = await _dsTableManager.DoSFP(query, sortPropertyName, sortDesending, filters, page, rowsPerPage);

        //Render the rows of the table
        var rows = new List<string>();
        var row = 0;
        foreach (var model in query)
        {
            row++;
            //you can pass view data to the row razor page for custom rows
            ViewData["Row"] = row;
            //use the RenderRow function to render the row.cshtml
            //if you leave the customRowView argument empty it will render the default row.cshtml
            rows.Add(await _dsTableManager.RenderRow(model, ViewData, customRowView: "Gateway/IndexRow"));
        }
        //return the rendered rows with Json function
        return await _dsTableManager.Json(rows, tableName);
    }
    //what ever json you return here will be rendered as the table body
    return Json("invalid table name");
}

public async Task<JsonResult> DSGetTableDataCount(string tableName, string filters, string routeValues = null)
{
    //write the same code from the DSGetTableData function to here exept the DoSFP function
    if (tableName == "custom-table")
    {
        var query = _gatewayAccountManager.GatewayAccountQuery;
        var routeValuesParsed = JsonConvert.DeserializeObject<List<KeyValuePair<string, object>>>(routeValues);
        var userId = (string?)routeValuesParsed?.Where(x => x.Key == "userId").FirstOrDefault().Value;
        if (userId == null)
        {
            return Json("user most not be null!");
        }
        query = query.Where(g => g.UserId == new Guid(userId));
        
        //Instead of DoSFP use the CountData function
        var count = await _dsTableManager.CountData(query, filters);
        return await _dsTableManager.Json(count, tableName);
    }
    return await _dsTableManager.Json(0, tableName);
}
}
  1. use the <table></table> tag like this to make your table:
@{
    var modelProperties = new List<string>
    {
        nameof(ModelType.Name),
        nameof(ModelType.Type),
        nameof(ModelType.MerchantId),
    };
}
<table ds-model-type="typeof(ModelType)"
       ds-controller="@nameof(ModelController).Replace("Controller","")"
       ds-name="custom-table"
       ds-rows-per-page="10"
       ds-pre-columns="1" //extra collumns to render at header and footer's start
       ds-post-columns="1" //extra collumns to render at header and footer's end
       ds-properties-to-show="modelProperties" //this will generate the header too
       ds-route-values="@(new []{new KeyValuePair<string,object>("userId",Model.Id)})"></table>
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5.1 239 4/10/2025
1.0.5 212 4/10/2025
1.0.4.5 182 3/28/2025
1.0.4.4 202 3/18/2025
1.0.4.1 197 3/18/2025
1.0.4 198 3/17/2025
1.0.3.2 193 3/17/2025
1.0.3 226 3/8/2025
1.0.2.5 161 2/24/2025
1.0.2.4 181 2/24/2025
1.0.2.3 157 2/24/2025