Skip to content

DataGrid TemplateColumn

New Discussion
Kevin O'Donvovan
Kevin O'Donvovan asked on Oct 6, 2020 7:27 AM

This seems way more complicated than it should be. In the specific example I'm working on I just want a cell to display a link to another page. As far as I can tell, I need to write a javascript callback to handle this – I was hoping the demo page was just using js, well, because, but I can't specify a C# callback in the markup. Even if I could the TemplateCellUpdatingEventArgs class doesn't appear to match the description on the demo page when I try to use it in C#. I think things like this are better handled in the markup anyway. Here's how I can achieve the same thing in the DevExpress grid I've been using until I could use your components:

                        
                            
                                @{
                                    var record = dtCont as MeterListItem;
                                    @record.Name
                                }
                            
                        

Sign In to post a reply

Replies

  • 0
    Kevin O'Donvovan
    Kevin O'Donvovan answered on Oct 5, 2020 3:50 PM

    I saw Andrew's response to a similar question earlier, and at first it seemed to work, but there are still problems with it. See the attached project, which simply uses a <span> with some static text in the template. The problem I'm seeing is that the template is not rendered in every row, and in fact the rows in which it is rendered change as the data is scrolled on and off the screen. You can see the effect in this screencast. Note that the last column  is initially blank until I scroll to the bottom, then when I return to the top it now has a value in the third row.

    One other thing I've noticed a few times is that whilst using the grid I'll occasionally get a "reconnecting to server" message. You can see this just near the end as teh grid freezes as I scroll it back up to the top (the message is off the top of the screencast)

    4201.GridProblem.zip

  • 0
    Andrew Goldenbaum
    Andrew Goldenbaum answered on Oct 5, 2020 8:50 PM

    Hello Kevin,

    I would like you to take a look at the attached sample project that demonstrates setting up a TemplateColumn in the DataGrid in Blazor. Essentially in order to do this, you need to provide a <Template> object within the tags of the TemplateColumn. Inside the <Template> tags, you can provide your content.

    It is also worth noting that at the time of writing this, there is a known issue that has been fixed internally in that the DataGridModule is not loading the correct stuff for usage of the <Template> object, and so you need to register a module for one of our other controls in order to use this. This is why the SparklineModule is registered in the sample project.

    Hope this helps! Please let me know if you have any other questions or concerns on this matter.

    DataGridTemplateAndFormatDemo.zip

    • 0
      Kevin O'Donvovan
      Kevin O'Donvovan answered on Oct 5, 2020 9:03 PM

      Hi Andrew, I'll take a look at the project you supplied, but I suspect its what I'm already doing. From the project I attached you can see i'm doing the following:

                      
                          

      I've also included the SparklineModule already, after seeing your reply to another user. It did initially seem to fix the problem, but as can be seen in the screencast and my attached example problem, there are still issues. I haven't tested this yet, but it may possibly be related to the grid having enough rows to require scrollbars. The first example I tried it on had only a handful of rows and worked perfectly. The first time I noticed the problem was when the grid had several pages of rows

      Just done a few tests. It's not the scrolling. It seems to work fine every time with seven rows or less in my datasource. Eight rows or more though, and the column is blank. Get enough rows to allow scrolling though, and you can make rows appear by scrolling them on and off the page

      • 0
        Kevin O'Donvovan
        Kevin O'Donvovan answered on Oct 5, 2020 9:15 PM

        Attached is my version of your component – it's on the Test page accessible from the navbar. I'd be interested to know what behaviour you observe if you run it?

        GridProblem_2D00_Andrew.zip

      • 0
        Kevin O'Donvovan
        Kevin O'Donvovan answered on Oct 5, 2020 9:25 PM

        That's annoying. I posted a response based on running your template, but it didn't post. Just tried again and I see I'm getting an error from the site when I try to post it. I'll try again here:

        I ran your project and it rendered correctly, despite having ten rows. I copied your component into a server side blazor project and it failed to render the template. Seems like there maybe an issue with server side that doesn't manifest in client side?

        And check this screen recording out – it seems to back up the server side blazor finding. Every time the problem manifests, in your component or mine, I get the reconnecting to server message – take a look: http://www.screencast.com/…/y0jeMmGpnbTg

      • 0
        Andrew Goldenbaum
        Andrew Goldenbaum answered on Oct 6, 2020 1:59 AM

        Hello Kevin,

        While I am rather unsure of what exactly causes the “Reconnecting to Server” message, I was able to get around it after speaking with one of my colleagues. It appears that the DataGrid is sending larger messages than SignalR allows by default, especially when using TemplateColumns as TemplateColumns tend to be rather expensive. After increasing the row count in your sample project, I see this behavior within it and this behavior interrupts the code-flow of the grid.

        In order to get around this, you can add the following lines of code within the Startup.cs file’s ConfigureServices method:

        services.AddSignalR(e => {
            e.MaximumReceiveMessageSize = 102400000;
        });

        While I am not personally too sure exactly what this does under the hood, I was told by my colleagues that this allows much larger messages to go through without requiring a “reconnect” to the server message, and the grid works as expected.

        Please let me know if you have any other questions or concerns on this matter.

      • 0
        Kevin O'Donvovan
        Kevin O'Donvovan answered on Oct 6, 2020 7:27 AM

        Thanks Andrew, that makes sense, yes. I've just added it to my test project and I can confirm it has fixed the problem(s). Thanks again. This was the most serious of the issues I've had, so really good to get it resolved

      • 0
        Mekimi San
        Mekimi San answered on Sep 5, 2022 3:02 PM

        You need to know that wordle today combines the best of word searching and word-related games making for a truly challenging and addictive experience!
        Keeping a wordle today winning streak alive can be tough. With only six tries to guess the daily answer, your choice of a starting word is key. Wordle literally keeps me up at night. Even though I should go to bed earlier, I almost always stay awake until just past midnight every night to solve the day's new Wordle Today puzzle.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Kevin O'Donvovan
Favorites
0
Replies
7
Created On
Oct 06, 2020
Last Post
3 years, 5 months ago

Suggested Discussions

Tags

Created by

Created on

Oct 6, 2020 7:27 AM

Last activity on

Oct 6, 2020 7:27 AM