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. Image for the cookie policy date

Retrieving datasource of a datamanger in javascript

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 : ""
    });
}

1 Reply

BM Balaji M Syncfusion Team July 21, 2016 02:24 PM UTC

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


Loader.
Up arrow icon