[CLOSED] How to create Ext.net grid panel dynamically at client side

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] How to create Ext.net grid panel dynamically at client side

    Hi,

    I have been using ext.net Mvc + razor in my application. Can you please provide code sample for grid panel creation at client side.
    I need to add listeners and load store data using ajax calls. For example..... following is the code for grid with razor syntax. Almost same kind of grid I want to create at client side dynamically.

      @(Html.X().GridPanel()
                    .ID("grdBusinessUnits")
                    .Cls("grd-existing-goals")
                    .Border(false)
                    .Height(280)
                    .Width(210)
                    .SelectionMemory(false)
                    .Store(Html.X().Store().ID("BusinessUnitsStore").Listeners(ls => ls.Load.Fn = "SelectBusinessUnits")
                                    .AutoLoad(false)
                                    .Model(Html.X().Model().ID("BusinessUnitsModel")
                                                   .IDProperty("Org_Level_Id")
                                                   .Fields(
                                                            new ModelField("Org_Level_Id", ModelFieldType.Int) { Mapping = "Org_Level_Id" },
                                                            new ModelField("Org_Level_Desc", ModelFieldType.String) { Mapping = "Org_Level_Desc" }
                                                           )
                                            )
                                    .Proxy(Html.X().AjaxProxy()
                                                    .Url(Url.Action("GetBusinessUnits"))
                                                    .Reader(Html.X().JsonReader().Root("data"))
                                          )
                                    .Parameters(
                                                  ps => ps.Add(new StoreParameter("regionCSV", "App.hdnRegionIds.value", ParameterMode.Raw))
                                               )
    
                         ).EmptyText("No records found. Please select a region to see related business units")
                    .ColumnModel(
                                    Html.X().Column().Text(Resource.Talent.LinkedHierarchies.BusinessUnitsText).Width(160).DataIndex("Org_Level_Desc")
                                )
                    .SelectionModel(Html.X().CheckboxSelectionModel().ID("chkBusinessUnitsSelect")
                                        .Mode(SelectionMode.Multi)
                                        .SelectedRecordID("Org_Level_Id")
                                        .CheckOnly(true)
                                        .Listeners(ls =>
                                        {
                                            ls.Select.Handler = "if (!this.selectLock){ BusinessUnitSelect(this,record,index); }";
                                            ls.Deselect.Handler = " if (!this.deselectLock){ BusinessUnitDeselect(); }";
                                        }
                                                  )
                                    )
                 )
    Last edited by Daniil; Apr 26, 2013 at 5:38 AM. Reason: [CLOSED]
  2. #2
    Hi @alscg,

    It is easy to get the script that you need.

    Open this Razor view in a browser, then look at the Page Sources. You will see a required script.

    Here are some detailed steps.
    http://forums.ext.net/showthread.php?20673#post89172
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @alscg,

    It is easy to get the script that you need.

    Open this Razor view in a browser, then look at the Page Sources. You will see a required script.

    Here are some detailed steps.
    http://forums.ext.net/showthread.php?20673#post89172
    Danill,

    I want to create/generate grid as mentioned above at client side using script. Please provide code sample.
  4. #4
    Have you not tried my suggestion?

    You would get something like this.

    Ext.create("Ext.grid.Panel", {
        store: {
          model: Ext.define("App.BusinessUnitsModel", {
            extend: "Ext.data.Model",
            fields: [{
              name: "Org_Level_Id",
              mapping: "Org_Level_Id",
              type: "int"
            }, {
              name: "Org_Level_Desc",
              mapping: "Org_Level_Desc",
              type: "string"
            }
                    ],
            idProperty: "Org_Level_Id"
          }),
          storeId: "BusinessUnitsStore",
          readParameters: function (operation) {
            return {
              apply: {
                "regionCSV": App.hdnRegionIds.value
              }
            };
          },
          proxy: {
            type: "ajax",
            reader: {
              type: "json",
              root: "data"
            },
            url: "/Razor/GetBusinessUnits"
          },
          listeners: {
            load: {
              fn: SelectBusinessUnits
            }
          }
        },
        id: "grdBusinessUnits",
        border: false,
        cls: "grd-existing-goals",
        height: 280,
        renderTo: "App.grdBusinessUnits_Container",
        width: 210,
        columns: {
          items: [{
            width: 160,
            dataIndex: "Org_Level_Desc",
            text: "Resource.Talent.LinkedHierarchies.BusinessUnitsText"
          }
                 ]
        },
        emptyText: "No records found. Please select a region to see related business units",
        selModel: window.App.chkBusinessUnitsSelect = Ext.create("Ext.selection.CheckboxModel", {
          proxyId: "chkBusinessUnitsSelect",
          selType: "checkboxmodel",
          listeners: {
            deselect: {
              fn: function (item, record, index) {
                if (!this.deselectLock) {
                  BusinessUnitDeselect();
                }
              }
            },
            select: {
              fn: function (item, record, index) {
                if (!this.selectLock) {
                  BusinessUnitSelect(this, record, index);
                }
              }
            }
          },
          checkOnly: true
        }),
        selectionMemory: false
      });
  5. #5
    Quote Originally Posted by Daniil View Post
    Have you not tried my suggestion?

    You would get something like this.

    Ext.create("Ext.grid.Panel", {
        store: {
          model: Ext.define("App.BusinessUnitsModel", {
            extend: "Ext.data.Model",
            fields: [{
              name: "Org_Level_Id",
              mapping: "Org_Level_Id",
              type: "int"
            }, {
              name: "Org_Level_Desc",
              mapping: "Org_Level_Desc",
              type: "string"
            }
                    ],
            idProperty: "Org_Level_Id"
          }),
          storeId: "BusinessUnitsStore",
          readParameters: function (operation) {
            return {
              apply: {
                "regionCSV": App.hdnRegionIds.value
              }
            };
          },
          proxy: {
            type: "ajax",
            reader: {
              type: "json",
              root: "data"
            },
            url: "/Razor/GetBusinessUnits"
          },
          listeners: {
            load: {
              fn: SelectBusinessUnits
            }
          }
        },
        id: "grdBusinessUnits",
        border: false,
        cls: "grd-existing-goals",
        height: 280,
        renderTo: "App.grdBusinessUnits_Container",
        width: 210,
        columns: {
          items: [{
            width: 160,
            dataIndex: "Org_Level_Desc",
            text: "Resource.Talent.LinkedHierarchies.BusinessUnitsText"
          }
                 ]
        },
        emptyText: "No records found. Please select a region to see related business units",
        selModel: window.App.chkBusinessUnitsSelect = Ext.create("Ext.selection.CheckboxModel", {
          proxyId: "chkBusinessUnitsSelect",
          selType: "checkboxmodel",
          listeners: {
            deselect: {
              fn: function (item, record, index) {
                if (!this.deselectLock) {
                  BusinessUnitDeselect();
                }
              }
            },
            select: {
              fn: function (item, record, index) {
                if (!this.selectLock) {
                  BusinessUnitSelect(this, record, index);
                }
              }
            }
          },
          checkOnly: true
        }),
        selectionMemory: false
      });

    Danill,

    Thank you...It is very helpful.

    Do I need to replace Ext with Ext.Net?
  6. #6
    Quote Originally Posted by alscg View Post
    Do I need to replace Ext with Ext.Net?
    Within the JavaScript code? No, you should not.
  7. #7
    Quote Originally Posted by alscg View Post
    Danill,

    Thank you...It is very helpful.

    Do I need to replace Ext with Ext.Net?
    With above code I am trying generate grid as below. to remove complexity I have commented out some portion of the code.
    I have div in the page and wants to add created grid to that div...so I changed renderTo property in the code
    @model List<Empower.DTO.Talent.GoalDTO>
    @{
        ViewBag.Title = "GoalManager";
        Layout = "~/Views/Shared/_LayoutPage.cshtml";
    }
    <script>
        $(document).ready(function () {
            LoadGrid();
        });
    
        function LoadGrid() {
            Ext.create("Ext.grid.Panel", {
                store: {
                    model: Ext.define("App.LevelModel", {
                        extend: "Ext.data.Model",
                        fields: [{
                            name: "Org_Level_Id",
                            mapping: "Org_Level_Id",
                            type: "int"
                        }, {
                            name: "Org_Level_Desc",
                            mapping: "Org_Level_Desc",
                            type: "string"
                        }
                        ],
                        idProperty: "Org_Level_Id"
                    }),
                    storeId: "LevelStore",
                    readParameters: function (operation) {
                        return {
                            apply: {
                                "regionCSV": "5"
                            }
                        };
                    },
                    proxy: {
                        type: "ajax",
                        reader: {
                            type: "json",
                            root: "data"
                        },
                        url: "/Talent/GetBusinessUnits"
                    }//,
                    //listeners: {
                    //    load: {
                    //        fn: SelectBusinessUnits
                    //    }
                    //}
                },
                id: "grdLevel",
                border: false,
                cls: "grd-existing-goals",
                height: 280,
                renderTo: "App.dynamicGrid",
                width: 210,
                columns: {
                    items: [{
                        width: 160,
                        dataIndex: "Org_Level_Desc",
                        text: "Resource.Talent.LinkedHierarchies.BusinessUnitsText"
                    }
                    ]
                },
                //emptyText: "No records found. Please select a region to see related business units",
                //selModel: window.App.chkBusinessUnitsSelect = Ext.create("Ext.selection.CheckboxModel", {
                //    proxyId: "chkBusinessUnitsSelect",
                //    selType: "checkboxmodel",
                //    listeners: {
                //        deselect: {
                //            fn: function (item, record, index) {
                //                if (!this.deselectLock) {
                //                    BusinessUnitDeselect();
                //                }
                //            }
                //        },
                //        select: {
                //            fn: function (item, record, index) {
                //                if (!this.selectLock) {
                //                    BusinessUnitSelect(this, record, index);
                //                }
                //            }
                //        }
                //    },
                //    checkOnly: true
                //}),
                //selectionMemory: false
            });
        }
    </script>
    
    <div id="dynamicGrid">
    </div>
  8. #8
    I think you should not use "App" for the div.

    Please try:
    renderTo: "dynamicGrid"
  9. #9
    Quote Originally Posted by Daniil View Post
    I think you should not use "App" for the div.

    Please try:
    renderTo: "dynamicGrid"
    I tried that also..but No luck. Please help in this reagrd.
  10. #10
    Is there any JavaScript error?
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] How I can create a CalendarPanel in client side?
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 18, 2012, 4:51 PM
  2. Replies: 0
    Last Post: May 01, 2012, 9:43 AM
  3. Replies: 6
    Last Post: Mar 13, 2012, 10:30 AM
  4. How to Create MultiCombo at client side?
    By zhangsir199 in forum 1.x Help
    Replies: 4
    Last Post: Aug 20, 2010, 5:53 AM
  5. Create Simple Store and Bind to Grid Client-Side?
    By Tbaseflug in forum 1.x Help
    Replies: 4
    Last Post: Oct 30, 2009, 5:27 PM

Posting Permissions