jQuery UI Widgets Forums Grid What's wrong in my dropdownlist column in grid?

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 10 years, 11 months ago.

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

  • snowyl
    Member

    I want create a dropdownlist column in grid. If I use array as data source, all is right. But when I change to json data,it is always display the value not label. the code is:
    //dropdownlist data from array
    var target = [
    { value: “0”, label: “——” },
    { value: “1”, label: “1:Price Analysis” },
    { value: “2”, label: “2:Price update” }
    ]
    var targetSource =
    {
    datatype: “array”,
    datafields: [
    { name: ‘label’, type: ‘string’ },
    { name: ‘value’, type: ‘string’ }
    ],
    localdata: target
    };
    var targetAdapter = new $.jqx.dataAdapter(targetSource, {
    autoBind: true
    });
    //dropdownlist data from json (CompanyID:1;Name:abc)
    var comurl = “ajax/company.ashx?ts=”+new Date();
    var comsource = {
    datatype: “json”,
    type: “POST”,
    datafields: [
    { name: ‘CompanyID’ , type: ‘int’},
    { name: ‘Name’ , type: ‘string’}
    ],
    id: ‘CompanyID’,
    url:comurl+”&action=GetSupplierName”
    }
    var comdataAdapter = new $.jqx.dataAdapter(comsource);
    //grid
    var source = {
    datatype: “json”,

    datafields: [
    { name: ‘PurchaseRequestID’ , type: ‘string’},
    { name: ‘company’, type: ‘string’ , value: ‘company’, values: { source: comdataAdapter,displayMember: “Name”, valueMember: “CompanyID”}},
    { name: ‘Target’, type: ‘string’ , value: ‘Target’, values: { source: targetAdapter.records, value: ‘value’, name: ‘label’ }}
    ],
    id: ‘PurchaseRequestID’,
    url:url,
    sortcolumn: ‘PurchaseRequestID’,
    sortdirection: ‘asc’
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    $(“#jqxgrid”).jqxGrid(
    {
    width: 1000,
    source: dataAdapter,
    theme: theme,
    sortable: true,
    filterable: true,
    altrows: true,
    selectionmode: ‘singlerow’,
    autorowheight: true,
    enabletooltips: true,
    columnsresize: true,
    columns: [
    { text: ‘PurchaseRequestID’, dataField: ‘PurchaseRequestID’, width: 100 },
    { text: ‘Company’, dataField: ‘company’, displayfield: ‘company’, columntype: ‘dropdownlist’,
    createeditor: function (row, value, editor) {
    editor.jqxDropDownList({ source: comdataAdapter,displayMember: “Name”, valueMember: “CompanyID”});} , width: 200 },
    { text: ‘HasBom’, dataField: ‘HasBom’, columntype: ‘checkbox’, width: 40 },
    { text: ‘Target’, dataField: ‘Target’, displayfield: ‘Target’, columntype: ‘dropdownlist’,
    createeditor: function (row, value, editor) {
    editor.jqxDropDownList({ source: targetAdapter, displayMember: ‘label’, valueMember: ‘value’ })} , width: 150 }
    ]
    };
    The data get from server are:
    PurchaseRequestID:1;company:1;companyname:abc;Target:0
    The comapny display in grid alway “1” not “abc”. But the Target display “—–“.
    What is wrong with my code?
    Thank you.


    Peter Stoev
    Keymaster

    Hi,

    The Foreign Key Column is not created correctly. The values field’s source member expects an Array i.e comdataAdapter.records and you should also make sure that comdataAdapter.records.length is more than 0 i.e comsource.async should be false.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.