How to add data from MSSQL to Ext.Net 7.2.0 classic

122 Views Asked by At

I'm new here on everything which is .Net. I have experience with ExtJs, but this is my first time creating an webtool with Ext.Net and i have a little problem which i dont get how to fix it. I have an webtool which has an TreeGrid where the data is get from the MSSQL and is populate correctly. After clicking on a child from that treegrid, an formpanel will show up with some tabs. On those tabs it will be some textfields with a gridpanel. My problem is that i can't bring the data for GridPanel. I dont understand what i'm doing wrong. I'm using the Ext.Net v7.2.0 Classic.

I will drop below a few codes to see what i'm talking about.

Here is the GridPanel View:

                            <ext-container layout="HBox">
                                <defaults>
                                    <ext-add key="header" value="false" mode="Raw" />
                                    <ext-add key="frame" value="true" mode="Raw" />
                                    <ext-add key="width" value="100" mode="Raw" />
                                </defaults>
                                <items>


                                    <!-- Configure a GridPanel and reference the Store above -->
                                    <ext-gridPanel 
                                                    title="Grouped Header"
                                                   width="800"
                                                   height="300"
                                                   frame="true">
                                        <!-- Configure a Store -->
                                        <store>
                                            <ext-store id="Store1" data="Model.GridPanel" autoLoad="true">
                                                        <fields>
                                                            <ext-integerDataField name="CommentId"/>
                                                            <ext-integerDataField name="CompensationPeriodKey"/>
                                                            <ext-stringDataField name="Title" />
                                                            <ext-stringDataField name="Comment" />
                                                            <ext-booleanDataField name="Print" />
                                                        </fields>
                                            </ext-store>
                                        </store>
                                        <columns>
                                            <ext-column text="#" dataIndex="CommentId"  />
                                            <ext-column text="Print" dataIndex="Print" />
                                            <ext-column text="Title" dataIndex="Title" />
                                            <ext-column text="Comment" dataIndex="Comment" flex='1' />
                                        </columns>
                                        <bbar>
                                            <ext-toolbar>
                                                <items>
                                                    <ext-button text="Print" iconCls="x-md md-icon-print" handler="this.up('grid').print();" />
                                                </items>
                                            </ext-toolbar>
                                        </bbar>
                                    </ext-gridPanel>
                                </items>
                            </ext-container>

And here is the Controller:

namespace MyApp.Controllers
{
    public class Controller: Controller
    {
        public IActionResult Index(int compPeriod)
        {
            // load entity for selected key
            TREEGRID entity = null;
            using (var context = new MyDbContext())
            {
                entity = context.TREEGRID.Include(per => per.GridPanel).FirstOrDefault(per => per.DataPeriodKey == compPeriod);
            }
            return View("Index", entity);
        }
    }
}

And my return is: enter image description here

1

There are 1 best solutions below

1
Fei Han On BEST ANSWER

My problem is that i can't bring the data for GridPanel. I dont understand what i'm doing wrong. I'm using the Ext.Net v7.2.0 Classic.

I did a test using the code that you shared with some testing data, which work well for me.

var model = new MyGridViewModel
{
    GridPanel = new List<object>
    {
        new object[] { 1, 1, "Title 1", "Hello", true },
        new object[] { 2, 2, "Title 2", "Hello World", false }
    }
};

return View("Index", model); 

Output

enter image description here

To troubleshoot the issue, please debug your code and check if the actual data in entity that you retrieved from DB look like above testing data.

entity = context.TREEGRID.Include(per => per.GridPanel).FirstOrDefault(per => per.DataPeriodKey == compPeriod);