Grid: load data only on demand

Hello,

There is a way to configure the Grid Control to load the data only with the code gridObj1.refreshContent(); and WebMethodAdaptor? I don't want the grid to load the data at begining.

Thanks!

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team November 6, 2015 09:25 AM UTC

Hi Jorge,

We can bind the dataSource to the Grid later using setModel, after binding the empty dataSource to the Grid at initial render. Please refer to the below code example.

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">

    <ej:button id="ButtonNormal" type="Button" runat="server" clientsideonclick="btnClick" text="Button"></ej:button>

    <ej:grid id="EmployeesGrid" runat="server" width="1500px" allowpaging="true">

                <!--DataSource is Empty at intial Render-->

                <Columns>

                        <ej:Column Field="OrderID" IsPrimaryKey="true" HeaderText="Order ID" Width="80" />

                        . . .  .

                </Columns>      

            </ej:grid>

    <script>

        function btnClick(e) {

            $("#MainContent_EmployeesGrid").ejGrid({ dataSource: ej.DataManager({ url: "Default.aspx/Data", adaptor: new ej.WebMethodAdaptor() }) })

        }

    </script>
</asp:Content>

[Code Behind]

[WebMethod]

        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]

        public static object Data(Syncfusion.JavaScript.DataManager value)

        {

            IEnumerable Data = OrderRepository.GetAllRecords();

            int count = Data.AsQueryable().Count();

            return new { result = Data, count = count };


        }


For your Convenience, we have prepared a sample that can be downloaded from the below location

Sample:  http://www.syncfusion.com/downloads/support/forum/121048/ze/EjGrid-312448390

Regards,
Seeni Sakthi Kumar S.

Loader.
Up arrow icon