This is a migrated thread and some comments may be shown as answers.

filtering do not work in a programmically build grid

11 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
lina fetisova
Top achievements
Rank 1
lina fetisova asked on 02 Dec 2010, 05:21 AM
Good day!
I have got such a grid

<telerik:RadGrid  ID="grReport" runat="server" GridLines="None" AllowFilteringByColumn="true" BorderWidth="0" BorderColor="White"
            AllowPaging="True" Culture="ru-RU" AllowAutomaticInserts="True" AllowAutomaticDeletes="false" AllowAutomaticUpdates="True" AllowMultiRowSelection="false"
            AllowSorting="True" ShowGroupPanel="true" Skin="Office2007"  AutoGenerateColumns="False" PageSize="100"
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="false"        
            Width="100%" Height="100%" GroupPanel-Width="100%" CssClass="MyGrid" onitemdatabound="grid_ItemDataBound">
        <GroupingSettings CaseSensitive="false" />        
        <MasterTableView TableLayout="Auto">
            <Columns>
                <telerik:GridBoundColumn ReadOnly="True" DataField="sales_id" HeaderText="Аптека" SortExpression="sales_id" UniqueName="sales_id" Visible="True" />
                <telerik:GridBoundColumn ReadOnly="True" DataField="preparation_name" HeaderText="Препарат" SortExpression="preparation_name" UniqueName="preparation_name" Visible="True"  />
                <telerik:GridBoundColumn ReadOnly="True" DataField="price_retail" HeaderText="Цена" SortExpression="price_retail" UniqueName="price_retail" Visible="True"  />
                <telerik:GridBoundColumn ReadOnly="True" DataField="avg_price" HeaderText="Средняя цена" SortExpression="avg_price" UniqueName="avg_price" Visible="True"  />
            </Columns>            
         </MasterTableView>    
         <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowDragToGroup="True">
            <Resizing  AllowColumnResize="true" AllowRowResize="true"/>
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
        </ClientSettings>
        <PagerStyle Mode="NextPrevAndNumeric" />
    </telerik:RadGrid>


And I bind the grid this way:

protected void Page_Load(object sender, EventArgs e)
        {
            var pr = new PriceLoader.PriceLoaderSoapClient();
            byte[] data = pr.GetDataForReport50();
            pr.Close();
            string xml = Decompressor.Decompress(data);
            var ds = new DataSet();
            var stringReader = new StringReader(xml);
            ds.ReadXml(stringReader);
            stringReader.Dispose();
            var table = ds.Tables[0];
            using (var repo = new SalesRepository())
                sales = repo.GetAllSoftVariant();
            grReport.DataSource = table;
            grReport.DataBind();

        }
        protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                var item = (GridDataItem)e.Item;
                var templ = (DataRowView)item.DataItem;
                var sales_id = Int32.Parse(templ["sales_id"].ToString());
                var sale = sales.FirstOrDefault(s => s.Id == sales_id);
                item["sales_id"].Text = sale != null ? sale.Name : String.Empty;
            }
        }


Sorting works well.
But filtering do not =(
Please can you tell me  what can I do to make filtering work?

yours respectfully, Lina

11 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Dec 2010, 07:33 AM
Hello Lina,

If you are using any advanced feature in grid(like sorting and filtering), then a better approach is using "AdvancedData binding" using NeedDataSource event. Set the DataSource in NeedDataSource event and RadGrid fires the NeedDataSource event each time it needs to be bound to a data source. For more information about this can be available here:

Grid / Advanced Data Binding
Advanced Data-binding (using NeedDataSource event)

Thanks,
Princy.
0
lina fetisova
Top achievements
Rank 1
answered on 02 Dec 2010, 11:50 AM
thank you, Princy, i've made this way:

 protected void grReport_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            var pr = new PriceLoader.PriceLoaderSoapClient();
            byte[] data = pr.GetDataForReport50();
            pr.Close();
            string xml = Decompressor.Decompress(data);
            var ds = new DataSet();
            var stringReader = new StringReader(xml);
            ds.ReadXml(stringReader);
            stringReader.Dispose();
            var table = ds.Tables[0];
            using (var repo = new SalesRepository())
                sales = repo.GetAllSoftVariant();
            grReport.DataSource = table;
        }

but id didn't help me =(((
0
lina fetisova
Top achievements
Rank 1
answered on 06 Dec 2010, 05:03 AM
any more ideas? =)
0
lina fetisova
Top achievements
Rank 1
answered on 09 Dec 2010, 10:00 AM
sorry, can anybody else help me?
0
Accepted
Pavlina
Telerik team
answered on 09 Dec 2010, 05:17 PM
Hi Lina,

I took the sample code you provided and put it in a sample page following a similar scenario you have.Attached to this message is the test project. In order to enable filtering of the grid i should remove the following line from your code:
 <ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>

Please examine it and let me know if you need additional assistance.

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
lina fetisova
Top achievements
Rank 1
answered on 10 Dec 2010, 06:23 AM
Pavlina, thank you very much! =) it began to work!=)
but filtering & sorting still do not work at columns which data appeared at itemdata bound.

for example:

<telerik:RadGrid ID="grReport" runat="server" GridLines="None" AllowFilteringByColumn="true" BorderWidth="0" BorderColor="White"
            AllowPaging="True" Culture="ru-RU" AllowAutomaticInserts="True" AllowAutomaticDeletes="false" AllowAutomaticUpdates="True" AllowMultiRowSelection="false"
            AllowSorting="True" ShowGroupPanel="true" Skin="Office2007"  AutoGenerateColumns="false" PageSize="100"
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="false"  
            Width="100%" Height="100%" GroupPanel-Width="100%" CssClass="MyGrid" onitemdatabound="grid_ItemDataBound" OnNeedDataSource="grReport_NeedDataSource" >
       <GroupingSettings CaseSensitive="false" />        
        <MasterTableView TableLayout="Auto">
            <Columns>     
                <telerik:GridBoundColumn ReadOnly="True" DataField="source" HeaderText="Аптека" SortExpression="source" UniqueName="source" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />
                <telerik:GridBoundColumn ReadOnly="True" DataField="region" HeaderText="Регион" SortExpression="region" UniqueName="region" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />  
                <telerik:GridBoundColumn ReadOnly="True" DataField="city" HeaderText="Город" SortExpression="city" UniqueName="city" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />                      
                <telerik:GridBoundColumn ReadOnly="True" DataField="dtload" HeaderText="Дата загрузки" SortExpression="dtload" UniqueName="dtload"  DataFormatString="{0:d}" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%" />
                <telerik:GridBoundColumn ReadOnly="True" DataField="syn" HeaderText="Синонимов" SortExpression="syn" UniqueName="syn" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />  
                <telerik:GridBoundColumn ReadOnly="True" DataField="lex" HeaderText="Лексографич." SortExpression="lex" UniqueName="lex" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />  
                <telerik:GridBoundColumn ReadOnly="True" DataField="num" HeaderText="Число" SortExpression="num" UniqueName="num" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />  
                <telerik:GridBoundColumn ReadOnly="True" DataField="per" HeaderText="% разбора" SortExpression="per" UniqueName="per" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />
                <telerik:GridBoundColumn ReadOnly="True" DataField="numSyn" HeaderText="Синонимы аптеки" SortExpression="numSyn" UniqueName="numSyn" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />   
                <telerik:GridBoundColumn ReadOnly="True" DataField="notDone" HeaderText="Не разобрано" SortExpression="notDone" UniqueName="notDone" ShowFilterIcon="false" AutoPostBackOnFilter="true" FilterControlWidth="95%"  />   
            </Columns>
        </MasterTableView>
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowDragToGroup="True">
            <Resizing  AllowColumnResize="true" AllowRowResize="true"/>
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
        <PagerStyle Mode="NextPrevAndNumeric" />
    </telerik:RadGrid>


protected void grReport_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
var client = new Syncer.SyncerClient();
            var data = client.GetByCityAndRegion("");
            client.Close();

                    string xml = Decompressor.Decompress(data);
                    var ds = new DataSet();
                    var stringReader = new StringReader(xml);
                    ds.ReadXml(stringReader);
                    stringReader.Dispose();
                    DataTable table = ds.Tables[0];

            grReport.DataSource = table;
        }

protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                var item = (GridDataItem) e.Item;
                var templ = (DataRowView) item.DataItem;
                var sales_id = Int32.Parse(templ["source"].ToString());
                var sale = sales.FirstOrDefault(s => s.Id == sales_id);
                item["source"].Text = sale != null ? sale.Name : String.Empty;
                item["region"].Text = sale != null ? sale.City.Region.Name : String.Empty;
                item["city"].Text = sale != null ? sale.City.Name : String.Empty;
            }
        }


sorting & filtering do work at all columns instead of source, region & city columns =(
what can I do and what can I read about filtering & sorting ItemDataBound columns?

thank you very much
yours respectfully, Lina
0
Pavlina
Telerik team
answered on 10 Dec 2010, 04:18 PM
Hi Lina,

Can you please provide me with a details description of what exactly are you trying to achieve? This will allow me to point you in the right direction. 

Kind regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
lina fetisova
Top achievements
Rank 1
answered on 13 Dec 2010, 04:39 AM
Good day, Pavlina!
the reason of my problem is so, that we have got a lot of data located in three databases.
we use web services to get data from some databases, so that's difficult for me to build the grid with data obtained by using one sql query.
I get a data set form web service, bind it to the grid and then on itemdatabound event I fill some grid columns with data from my local database. This data is connected by a key with the grid data source. Everuthing is ok, but filtering and sorting do not work in this colums, which I fill on itemdatabound =( The columns i fill as grid.Datasource filters and sorts well.
What can I do to make my itemdatabound columns filters and sorts well?
0
lina fetisova
Top achievements
Rank 1
answered on 13 Dec 2010, 04:39 AM
yours respectfully, Lina
0
lina fetisova
Top achievements
Rank 1
answered on 14 Dec 2010, 06:46 AM
Sorry, Pavlina, any ideas?
0
Pavlina
Telerik team
answered on 14 Dec 2010, 03:32 PM
Hello Lina,

I am afraid that the desired functionality could not be achieved with RadGrid control. Generally the internal logic of the RadGrid when filtering and sorting are enabled is to retrieve the data from the DataSource to which
the grid is bound and therefore filtering will be applied only on the currently given data.

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
lina fetisova
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
lina fetisova
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or