GithubHelp home page GithubHelp logo

Comments (1)

gustavnavar avatar gustavnavar commented on May 21, 2024

You can do it using the Width property of the selected column.

The accepted values of the Width property are strings with the units (e.g. "100px", "20em", etc.)

The following page allows you to change the size of the first column of the grid ("OrderID").

@page "/"
@using GridBlazorServerSide.ColumnCollections
@using GridBlazorServerSide.Models
@using GridBlazorServerSide.Resources
@using GridBlazorServerSide.Services
@using Microsoft.Extensions.Primitives
@using System.Globalization
@using System.Threading.Tasks
@inject IOrderService orderService

<h1>Grid Sample</h1>

<p>
    This page contains a basic grid
</p>

<p>
    This component demonstrates a GridBlazor server-side grid. For more information, please see: <a href="https://github.com/gustavnavar/Grid.Blazor">https://github.com/gustavnavar/Grid.Blazor</a>
</p>

@if (_task.IsCompleted)
{
    <div class="row" style="margin-bottom:10px;">
        <label class="control-label col-md-1"><b>Col widtj</b></label>
        <div class="col-md-2">
            <input class="form-control" @bind="_colWidth" @onkeyup="InputColWidthKeyup" @onclick:stopPropagation />
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <GridComponent T="Order" Grid="@_grid"></GridComponent>
        </div>
    </div>
}
else
{
    <p><em>Loading...</em></p>
}

@code
{
    private CGrid<Order> _grid;
    private Task _task;
    private string _colWidth;

    protected override async Task OnParametersSetAsync()
    {
        var locale = CultureInfo.CurrentCulture;
        SharedResource.Culture = locale;

        var columnCollections = new ColumnCollections();
        var query = new QueryDictionary<StringValues>();
        var client = new GridClient<Order>(q => orderService.GetOrdersGridRows(ColumnCollections.OrderColumns, q),
            query, false, "ordersGrid", ColumnCollections.OrderColumns, locale)
            .Sortable()
            .Filterable()
            .SetStriped(true)
            .WithMultipleFilters()
            .WithGridItemsCount();

        _grid = client.Grid;
        // Set new items to grid
        _task = client.UpdateGrid();
        await _task;
        var column = ((ICGrid)_grid).Columns.SingleOrDefault(r => r.Name == "OrderID");
        _colWidth = column.Width;
    }

    public void InputColWidthKeyup(KeyboardEventArgs e)
    {
        if (e.Key == "Enter")
        {
            var column = ((ICGrid)_grid).Columns.SingleOrDefault(r => r.Name == "OrderID");
            column.Width = _colWidth;
        }
    }
}

from grid.blazor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.