We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Retrieving datasource of a datamanger in javascript

Thread ID:

Created:

Updated:

Platform:

Replies:

125097 Jul 20,2016 11:27 AM Jul 21,2016 10:24 AM JavaScript 1
loading
Tags: ejDataManager
Lewis Hamill
Asked On July 20, 2016 11:27 AM

I have defined the adaptor of the DataManager as JsonAdaptor in my markup and assigned the datasource in my code behind. I then want to retrieve that datasource from the DataManager in javascript.

How do I reference the DataManager in javascript and retrieve the datasource?

Sample code below:

Markup

<ej:DataManager ID="dmSuppliers" runat="server" Text="DataManager" Adaptor="JsonAdaptor" />

.CS

private void BindSupplierDataManager()
{
    var suppliers = new List<IdStringPair>()
    {
        new IdStringPair(1, "Magenta"),
        new IdStringPair(2, "Trans"),
        new IdStringPair(3, "SuperSupplier")
    };
    dmSuppliers.Json = suppliers;
}

JS

function writeSupplierName(args) {
    var dropData = [
        //Retrieve datasource from datamanager
    ];
    var selIndex = [];
    if (args.rowdata != undefined) {
        for (j = 0; j < dropData.length; j++) {
            if (args.rowdata["SupplierName"] == dropData[j]) {
                selIndex.push(j);
                break;
            }
        }
    }
    args.element.ejDropDownList({
        width: "100%",
        dataSource: dropData,
        fields: { id: "text", text: "text", value: "value" },
        selectedItems: args.rowdata !== undefined ? selIndex : ""
    });
}

Balaji M [Syncfusion]
Replied On July 21, 2016 10:24 AM

Hi Lewis Hamill,

 

Thank you for contacting Syncfusion support.

 

You can retrieve the data from DataManager in done event which will be trigger while execute the query.

 

Please construct your ej.Query() to retrieve record and pass the query object to ej.Datamanager() .  You can access the DataManager by access the window object like  "window.{DataManager ID}". In done event will return data in e.result object.

 

ASPX:

<ej:DataManager ID="FlatData" runat="server" URL="http://mvc.syncfusion.com/Services/Northwnd.svc/" EnableCaching="true" CachingPageSize="10" TimeTillExpiration="120000" />

 

JS:

<script type="text/javascript">

        $(function () {

 

            var query = ej.Query().from("Orders").page(1, 10).sortBy("OrderID desc");

            var data = window.FlatData.executeQuery(query).done(function (e) {

                            console.log(e.result.length);

                        });

 

        });

    </script>

 

Let us know if you have any queries.

 

Regards,

M. Balaji


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;