How to display a page like a Modal dialog

Posted by: soraroid on 15 July 2024, 4:20 am EST

    • Post Options:
    • Link

    Posted 15 July 2024, 4:20 am EST

    Hello.

    I am leaving a message because I have a question.

    1. I would like to open a pop-up window through Keypress in FlexGrid.

      For example, press F1 to display the customer inquiry screen in a pop-up window.

      I would like to import the selected customer information into FlexGrid.

      Because it is a query window to be used on multiple pages

      I would like to create the page in advance and use it like a Modal Dialog.

    2. How to use the mask function for cells in FlexGrid.

      (ex) --____ < It is like this

      I wish the format would be applied automatically as I type it)

    Please answer both with example sources.

  • Posted 17 July 2024, 4:13 am EST - Updated 17 July 2024, 4:18 am EST

    Hi,

    1. You could override the “OnKeyDown” method of the GridCellFactory Class and then handle the keypress of the “F1” key. By default, the browser handles the “F1” key press and you could prevent the default behaviour using JavaScript (handled in the sample).

    I have defined the “Inquiry” component and used it within the C1Dailog.

    1. For this requirement, you could define Custom Column and then use “C1MaskedTextBox” and then set the mask. You could refer to the following demo on Custom Columns: https://developer.mescius.com/componentone/demos/blazor/blazorexplorer/FlexGrid/CustomDropDownColumn

    References:

    Mask Property: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Input~C1.Blazor.Input.C1MaskedTextBox~Mask.html

    C1MaskedTextBox Class: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Input~C1.Blazor.Input.C1MaskedTextBox.html

    Kindly refer to the attached sample. Further, you could modify the sample as per your requirement. Let us know if you face any issues.

    Regards,

    Ankit

    Sample:

    FlexGrid-Text-Limit.zip

    Steps:

  • Posted 20 August 2024, 9:18 pm EST

    Hi.

    Thanks for the sample source.

    I have one more question.

    In the sample source, pressing F1 will work when you are in selection mode,

    but it will not work when in edit mode(when the cursor in blinking)

    I would like to know how the F1 key works in edit mode.

    Please answer with example sources.

  • Posted 22 August 2024, 1:33 am EST

    Hi,

    The “OnKeyDown” event is not triggered when the edit mode is activated. Another approach is to wrap the FlexGrid around a div and then handle the keydown using the JavaScript and then call the “C#” function. Kindly refer to the following code snippet and the attached sample:

    Index.razor:

    [JSInvokable("F1KeyHandler")]
    public void KeyHandler()
    {
        var row = grid.Selection.Row;
        var col = grid.Selection.Column;
        // Additionally end the edit of the Grid
        if(grid.ActiveEditor != null)
        {
            grid.FinishEditing();
        }
        if(!myPopup.IsOpened())
        {
            var selectedRow = grid.SelectedIndex;
            if (selectedRow != null)
            {
                // Set the selected forecast to the data context of the selected row
                var selectedForecast = grid.Rows[selectedRow].DataItem as WeatherForecast;
                if (selectedForecast != null && SetSelectedForecast != null)
                {
                    SetSelectedForecast(selectedForecast);
                    // Open the dialog
                    myPopup.Open();
                }
            }
        }
        Console.WriteLine("F1 Pressed at row: " + row + " and column: " + col);
    }

    _Layout.cshtml:

    function AddHandlers(dotNetObject) {
        var gridContainer = document.getElementById("gridContainer");
        // Add KeyDown Listener
        gridContainer.addEventListener("keydown", function (e) {
            if (e.key === "F1") {
                e.preventDefault();
                dotNetObject.invokeMethodAsync('F1KeyHandler');
            }
        }, true);
    }

    I have attached the modified sample. Let me know if you face any issues.

    Regards,

    Ankit

    FlexGrid-Text-Limit.zip

  • Posted 23 August 2024, 2:04 am EST

    Thank you for uploading the source.

    I am leaving a message because I have additional questions.

    If you set a breakpoint in KeyHandler and run it,

    Even though the F1 button is pressed only once,

    the KeyHandler is executed 5 times.

    Why does it run 5 times?

    How can I make it run only once?

  • Posted 23 August 2024, 5:29 am EST

    Hi,

    I apologize for the initial oversight. The issue arose from the event listeners being added on every component re-render. To ensure they’re only added once,update the OnAfterRenderAsync method as follows:

    
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            cf.MyPopup = myPopup;
            var dotNetReference = DotNetObjectReference.Create(this);
            this.JsRuntime.InvokeVoidAsync("AddHandlers", dotNetReference);
        }
    }

    This modification ensures the listeners are only added during the initial component render, preventing the event from being triggered repeatedly.

    Please refer to the attached modified sample for a working demonstration. If you continue to encounter issues, do let us know.

    Best regards,

    Ankit

    FlexGrid-Text-Limit.zip

  • Posted 25 August 2024, 8:12 pm EST

    Thank you for your reply.

    I have one more question.

    If you move and input using the keyboard insted of clicking with the mouse,

    you can see the row vaue, but the column value always appears as 0.

    How do I know which field is currently being entered?

  • Posted 26 August 2024, 3:07 am EST

    Hi,

    You could use the “CursorRange” property to get the Active Row and Column Indexes. And use the column index to get the Column Name.

    Kindly refer to the following code snippet and the attached sample:

            // Get the Active Column Index
            int activeCol = grid.CursorRange.Column;
            // Get the Column Name of the Active Field
            string columnName = grid.Columns[activeCol].ColumnName;

    CursorRange property: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.FlexGrid~CursorRange.html

    Let us know if you face any issues. Also, it is recommended that you create separate tickets/cases for separate queries. You could add the reference to the ticket/case if it is related or is extended from the ticket/case.

    Regards,

    Ankit

    FlexGrid-Text-Limit.zip

  • Posted 27 August 2024, 3:52 am EST

    Thank you for your reply.

    I have some additional questions.

    If you look at the attached source, I added CheckListBehavior,

    but the column is too wide, so I want to reduce the width.

    Is there a way to changed it to the size I want?

    FlexGrid-Text-Limit_Edit.zip

  • Posted 29 August 2024, 12:23 am EST

    Hi,

    It looks like you’ve already created a separate forum case at: https://developer.mescius.com/forums/blazor-edition/chechlistbehavior-is-too-wide.

    Our team has responded to that case, and any further discussion on this issue will take place there.

    Best regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels