Forum Discussion

scottcm's avatar
scottcm
New Contributor
12 years ago

Filtering a DevExpress XtraGrid's PopupList column

Below are simplified methods for setting a filter on a DevExpress XtraGrid column.  The code works when the column filter is a textbox, but it doesn't work when the column is a PopupList.  Any suggestions for how to handle that scenario?



function SetFilter(xtraGrid, columnId, filterValue)

{

    var column = GetColumn(xtraGrid, grid["DefaultView"], columnId);



    xtraGrid["DefaultView"]["SetFilterRowValue"](column, filterValue);

}





function GetColumn(grid, view, columnId)

{

    var columns;

    var col;



    if (view == null)

    {

        view = grid["DefaultView"];

    }



    columns = view["Columns"];



    if (aqObject["GetVarType"](columnId) == varOleStr)    // The column is specified by caption

    {

        for (var i=0; i<columns["Count"]; i++)

        {

            col = columns["Item_2"](i);

            if (col["Caption"]["OleValue"] == columnId)

            {

                return col;        // Column found

            }

        }

        return null;        // Column not found

    }

    else

    {

        return columns["Item_2"](columnId);    // The column is specified by index

    }

}

2 Replies

  • Anonymous's avatar
    Anonymous

    Do we have a Guru in Developer Express controls' testing? I think, there should be special properties/methods to access the needed entry.



    BTW, Scott, did you see the "Filter XtraGrid data" How To article? 
  • scottcm's avatar
    scottcm
    New Contributor
    I did see that code and it's the basis for the code I wrote.  I ended up figuring out the problem, but there is more than 1 possible solution.

    The easiest solution if you have control over the applications source code is to change the XtraGrid to filter by display text rather than value.  I didn't have that option so I created a check for the type of editor used by the column filter and based on that either used text or looked up the "Id" value of the selection.



    The code snippet ended up looking like this.

    column = GetGridColumn(grid, view, columnId);

    if (column["ColumnEdit"] != null && column["ColumnEdit"]["EditorTypeName"] == "PopupList")

    {

      filterValue = GetIdValueFromDataSource(column["ColumnEdit"]["DataSource"], displayText);

    }

    else if (column["ReadColumnEdit"]!=null && column["ReadColumnEdit"]["EditorTypeName"] == "PopupList")

    {

      filterValue = GetIdValueFromDataSource(column["ReadColumnEdit"]["DataSource"], displayText);

    }

    else

    {

      filterValue = displayText;

    }



    view["SetFilterRowValue"](column, filterValue);