API Reference for ejQuery

23 Jun 202013 minutes to read

Communicates with data source and returns the desired result based on the Query provided.

Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid; padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().take(5));
    var tableBody = ""; 
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity,="" dataManagerObj[i].freight);="" $(".table="" tbody").html(tableBody);};=""></3;i++){>

    Methods

    addParams(key, value)

    Passes custom parameters to our API URL.

    Name Type Description
    key string
    value string

    Returns:

    ej.Query

    Example

  • HTML
  • <script>
    var dataManagerObj = ej.DataManager({url: "http://mvc.syncfusion.com/Services/Northwnd.svc/Orders/"}).executeQuery(new ej.Query().addParams("test","value"));
    </script>

    clone()

    clone is used to duplicate the data.

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().where("OrderID","equal","10250").clone());
    var tableBody="";
    tableBody += String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", dataManagerObj[0].OrderID, dataManagerObj[0].CustomerID, dataManagerObj[0].ShipCity);
    $(".table tbody").html(tableBody);
    </script>

    execute(dataManager)

    It is used to execute the query on URL Binding

    Name Type Description
    dataManager object JSON data or OData

    Returns:

    JQueryPromise

    Example

  • HTML
  • <script>
    var dataManager = ej.DataManager({url: "http://mvc.syncfusion.com/Services/Northwnd.svc/Orders/"});
    var promise =  ej.Query().select(["OrderID", "CustomerID", "ShipName", "ShipCity", "Freight"]).execute(dataManager,done).take(3);
    promise.done(function(e){}) 
    </script>

    executeLocal(dataManager)

    It is used to execute the query on Local Binding

    Name Type Description
    dataManager object JSON data

    Returns:

    Array

    Example

  • HTML
  • <script>
    var dataManagerObj = ej.DataManager(window.gridData);
    var promise =  ej.Query().select(["OrderID", "CustomerID", "ShipName", "ShipCity", "Freight"]).executeLocal(dataManagerObj).take(3);
    </script>

    expand(tables)

    expand is used to performs complex binding.

    Name Type Description
    tables string name of the tables

    Returns:

    ej.Query

    Example

  • HTML
  • <script>
    var dataManagerObj = ej.DataManager({url: "http://mvc.syncfusion.com/Services/Northwnd.svc/"})
    .executeQuery(ej.Query().from("Orders").select("OrderID", "CustomerID", "ShipCity", "Employee.FirstName").expand("Employee"));
    </script>

    foreignKey(key)

    Relates two tables. A foreign key is a column or combination of columns which is used to establish and enforce a link between two tables.

    Name Type Description
    key string primary key field name

    Returns:

    ej.Query

    Example

  • HTML
  • <script>
    var dataManagerObj = ej.DataManager({url: "http://mvc.syncfusion.com/Services/Northwnd.svc/"})
    .executeQuery(ej.Query().from("Orders")
    .hierarchy(ej.Query().from("Order_Details").foreignKey("OrderID").sortBy("Quantity"),function () {
     return [10250, 10251, 10252, 10253] }));
    </script>

    from(tableName)

    Specifies the name of table(s) to retrieve data.

    Name Type Description
    tableName string name of the table

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().from("Orders"));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    group(fieldName)

    Groups records based on the given field name.

    Name Type Description
    fieldName string name of the column

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().group("CustomerID"));
    var tableBody="";
    for(var i=0;i<3;i++){ row="dataManagerObj[0].items[i];" tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," row.orderid,="" row.customerid,="" row.shipcity);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    hierarchy(query)

    Displays the records in hierarchical relationships. The foreign key is used to relate two tables.

    Name Type Description
    query ej.Query query the JSON data

    Returns:

    ej.Query

    Example

  • HTML
  • <script>
    var dataManagerObj = ej.DataManager({url: "http://mvc.syncfusion.com/Services/Northwnd.svc/"})
    .executeQuery(ej.Query().from("Orders")
    .hierarchy(ej.Query().foreignKey("OrderID").from("Order_Details"),function () {
     return [10248] }));
    </script>

    page(pageIndex, pageSize)

    Retrieves records based on the given page index and size.

    Name Type Description
    pageIndex number page number
    pageSize number Number of rows in the page

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    //page(pageIndex,pageSize)
    var dataManagerObj = ej.DataManager(window.employeeData).executeLocal(ej.Query().page(2,3));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].employeeid,="" dataManagerObj[i].lastname,="" dataManagerObj[i].firstname);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    range(start, end)

    The range property is used to retrieve the records based on the given start and end index.

    Name Type Description
    start number start index of JSON data
    end number end index of JSON data

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    //range(startIndex,endIndex)
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().take(20).range(2,5));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    requiresCount()

    Specifies that the total number of records(count) is required in the result.

    Returns:

    ej.Query

    Example

  • HTML
  • <script>
    var dataManagerObj =ej.DataManager(window.gridData).executeLocal(ej.Query().requiresCount());
    </script>

    search(fieldName, operator, value, ignoreCase,ignoreAccent)

    It is used to search the given search key value in JSON data

    Name Type Description
    fieldName string name of the column
    operator string conditional Operators
    value string value to filter the field name
    ignoreCase boolean on/off case sensitive.
    ignoreAccent boolean Filter diacritics based on the boolean value.

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().select(["OrderID","ShipCity","CustomerID"]).search("10251","OrderID","equal"));
    var tableBody="";
    tableBody += String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", dataManagerObj[0].OrderID, dataManagerObj[0].CustomerID, dataManagerObj[0].ShipCity);
    $(".table tbody").html(tableBody);
    </script>

    select(fieldName)

    Selects specified columns from the data source.

    Name Type Description
    fieldName string name of the columns

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().select(["OrderID","CustomerID","ShipCity"]));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    skip(nos)

    Skips the given count of records from the data source.

    Name Type Description
    nos number number of records

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.employeeData).executeLocal(ej.Query().skip(5));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].employeeid,="" dataManagerObj[i].lastname,="" dataManagerObj[i].firstname);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    sortBy(fieldName)

    Sort items or records in an ordered sequence.

    Name Type Description
    fieldName string name of the column

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().sortBy("CustomerID desc"));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    sortByDesc(fieldName)

    Sort items or records in descending order.

    Name Type Description
    fieldName string name of the column

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().sortByDesc("CustomerID"));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>

    take(nos)

    Picks the given count of records from the top of the datasource.

    Name Type Description
    nos number number of records

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().take(5));
    var tableBody="";
    for(var i=0;i<5;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity);="" $(".table="" tbody").html(tableBody);}=""></5;i++){>

    using(dataManager)

    using is a method used to query the data manager.

    Name Type Description
    dataManager Object Pass new data source

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData);
    var local = dataManagerObj.executeLocal(ej.Query().using(dataManagerObj).take(1));
    var tableBody = ""; 
     tableBody += String.format("<tr><td>{0}</td><td>{1}</td></tr>", local[0].OrderID, local[0].CustomerID);
     $(".table tbody").html(tableBody); 
    </script>

    where(fieldName, operator, value, ignoreCase,ignoreAccent)

    It is used to filter records based on the filter condition.

    Name Type Description
    fieldName string name of the column
    operator string conditional Operators
    value string value to filter the field name
    ignoreCase boolean on/off case sensitive.
    ignoreAccent boolean Filter diacritics based on the boolean value.

    Returns:

    ej.Query

    Example

  • HTML
  • <style>
    .table,tr,td{ border:1px solid;padding:3px;}
    </style>
    <table class="table" style="border-collapse:collapse">
    <tbody></tbody>
    </table>
    <script>
    var dataManagerObj = ej.DataManager(window.gridData).executeLocal(ej.Query().where("OrderID","lessthan","10253"));
    var tableBody="";
    for(var i=0;i<3;i++){ tableBody="" +="String.format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>"," dataManagerObj[i].orderid,="" dataManagerObj[i].customerid,="" dataManagerObj[i].shipcity);="" $(".table="" tbody").html(tableBody);}=""></3;i++){>