jQuery UI Widgets Forums Lists DropDownList binding to JSON data with parameter

This topic contains 6 replies, has 2 voices, and was last updated by  krnacm 10 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author

  • krnacm
    Participant

    Hello,

    I was wondering if it is possible binding to JSON data with parameter. I need to call ajax method ‘customers’ with some parameter.

    I have this code from your demo

    
    var url = "../sampledata/customers";
    // prepare the data
    var source =
    {
       datatype: "json",
       datafields: [
          { name: 'CompanyName' },
          { name: 'ContactName' }
       ],
       url: url,
       async: false
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    // Create a jqxDropDownList
    $("#jqxWidget").jqxDropDownList({
       selectedIndex: 0, source: dataAdapter, displayMember: "ContactName", valueMember: "CompanyName", width: 200, height: 25
    });
    

    I need to call ajax method with parameter id

    
    public JsonResult customers (string id){
    ....
    }
    

    Is it possible? If yes, any help will be much appreciated.

    Thanks in advance.

    Kind regards,
    Matej


    Peter Stoev
    Keymaster

    Hi Matej,

    You can use for that purpose either the source object’s data parameter set to JSON object or the formatData callback function of the dataAdapter. For more information visit: http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdataadapter/jquery-data-adapter.htm

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    krnacm
    Participant

    Hi Peter,

    thanks for your response. I’m checked the documentation to data adapter, but the documentation to source object is a bit strange, because there is writen that it contains a data property

      data: Data to be sent to the server

    but by creating source object is used property localData

    var data = [{ “empName”: “test”, “age”: “67”, “department”: { “id”: “1234”, “name”: “Sales” }, “author”: “ravi”}];

    // prepare the data
    var source =
    {
    datatype: “json”,
    datafields: [
    { name: ’empName’ },
    { name: ‘age’ },
    { name: ‘id’, map: ‘department>id’ },
    { name: ‘name’, map: ‘department>name’ },
    { name: ‘author’ }
    ],
    localdata: data};

    I tried to follow the documentation and created this code but it is not calling the ajax method ‘customers’. I added there the localdata property but now the method is not called at all.

    
    var url = "../sampledata/customers";
    // prepare the data
    var source =
    {
       datatype: "json",
       datafields: [
          { name: 'CompanyName' },
          { name: 'ContactName' }
       ],
       url: url,
       <strong>localdata: 'id=1',</strong>
       async: false
    };
    

    Am I doing something wrong or am I missing something?

    Thanks,

    Kind regards,
    Matej


    Peter Stoev
    Keymaster

    Hi Matej,

    localdata is for loading local data into jqxDataAdapter. You should use “data” for sending data to a server as it is explained in the documentation and in my previous post. You shouldn’t have localdata and url both set.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    krnacm
    Participant

    Hi Peter,

    I can not find where the “data” property is explained in the documentation. Please can you copy here the block of code from the documentation where it is explained?

    I guess it is somthing similar to this

    
    var source =
    {
        datatype: "json",
        datafields: [
            { name: 'empName' },
            { name: 'age' },
            { name: 'id', map: 'department>id' },
            { name: 'name', map: 'department>name' },
            { name: 'author' }
        ],
        data: 'id=1'
    };
    

    But I don’t know what type data property is for.

    Thanks,

    Kind regards,
    Matej


    Peter Stoev
    Keymaster

    Hi Matej,

    As I wrote, it should be set to a JSON object.

    Ex:

    var source =
    {
        datatype: "jsonp",
        datafields: [
            { name: 'countryName' },
            { name: 'name' },
            { name: 'population', type: 'float' },
            { name: 'continentCode' }
        ],
        url: "http://ws.geonames.org/searchJSON",
        data: {
            featureClass: "P",
            style: "full",
            maxRows: 50
        }
    };

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    krnacm
    Participant

    Hi Peter,

    thank you very much. I found it also in the documentation after your message. I solved it with the formatData callback function of the dataAdapter.

    Have a splendid day.

    Kind regards,
    Matej

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.