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

Using grid filtering from ItemCommand

4 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
golddog
Top achievements
Rank 1
golddog asked on 08 Sep 2008, 03:27 PM
Somthing simple, I'm just missing it.  We have a grid in which we provide link buttons on each item.  These buttons show another control for viewing or editing the item.

So, I handle the ItemCommand event of the grid and start the process to populate and show the edit/view control, it works great.

However, since we handle the ItemCommand event, filtering doesn't work, since we don't do anything with the FilterCommandName.  I'd like for it to simply use the grid's default filtering.  Just a simple brain lock, I'm sure, that I'm not seeing how to invoke the base filtering.

protected void grdQuestionPool_ItemCommand(object source, GridCommandEventArgs e){
    
if (e.CommandName.Equals(RadGrid.EditCommandName))
    {
        ViewOrEditQuestion(e);
    }
else if (e.CommandName.Equals(RadGrid.FilterCommandName)) {
        
??
    
}
}

4 Answers, 1 is accepted

Sort by
0
golddog
Top achievements
Rank 1
answered on 08 Sep 2008, 03:58 PM
I think I've decided that it's not anything to do with the ItemCommand after all.

We have several other places we're using grids and filtering works fine.  One difference was that these others don't require handling of the ItemCommand event, as they don't have linkbutton-type functionality.

So, I commented out where we wire up the ItemCommand event in the OnInit of the control I'm having trouble with, and the filtering still doesn't work.  I guess that was a red herring.

Comparing a working example and my problem example, the only other difference I see so far is that the data sources are different types of objects.  Both data sources are IEnumerable of their object types.

Something simple I'm overlooking, just haven't seen it yet I'm sure.
0
golddog
Top achievements
Rank 1
answered on 08 Sep 2008, 04:59 PM
I've got nothing.  Here's the non-filtering markup:

<telerik:RadGrid ID="grdQuestionPool" SkinID="MultirowSelect" EnableViewState="true" runat="server">
    
<ClientSettings>
        
<ClientEvents OnFilterMenuShowing="QuestionFilterMenuShowing" />
    
</ClientSettings>

    <MasterTableView DataKeyNames="QuestionID"> 
        
<NoRecordsTemplate>
            
No Questions available in Question Pool
        
</NoRecordsTemplate>
        
<Columns>
            
<telerik:GridBoundColumn HeaderText="Question Text" DataField="Text" UniqueName="colName" />
            
<telerik:GridCheckBoxColumn HeaderText="Soft Benefit" DataField="SoftBenefit" UniqueName="colSoftBenefit" />
            
<telerik:GridEditCommandColumn ButtonType="LinkButton" EditText="View/Edit" UniqueName="colEdit" />
        
</Columns>
    
</MasterTableView>
</telerik:RadGrid>

and the associated skin:

<

telerik:radgrid runat="server" 
    Skin
="GraphicDesign"
    
EnableEmbeddedSkins
="false"
    
AllowSorting="True" 
    AllowPaging
="true"
    
PageSize
="10"
    
AllowFilteringByColumn
="true"
    
AllowMultiRowSelection
="true"
    
AutoGenerateColumns
="False"
    
EnableAjaxSkinRendering
="true"
    
GridLines="Vertical" 
    GroupingEnabled
="False"
    
SkinID="MultirowSelect">

So it seems like filtering should be enabled and working.  I really don't understand what's going wrong.

0
golddog
Top achievements
Rank 1
answered on 08 Sep 2008, 08:15 PM
Aha!  I've finally found the difference between this grid and the ones which work, although I can't explain why this does not work.

In my presenter, when refreshing the questions, I have this code:

------------------

IEnumerable

<Question> questionPool = _questionService.ListQuestionsByTemplateDescriptors(descriptors);

if (View.EditedId.HasValue)
{
    questionPool = questionPool.Where(q => !q.TemplateQuestions.Select(tq => tq.TemplateID).Contains(View.EditedId.Value));
}

View.SetQuestionPoolDataSource(questionPool);

-------------------

What it's doing is getting the qualified questions.  If we're currently editing a Template, we further filter that IEnumerable to not include the questions which already belong to this Template (i.e., we're showing the questions eligible to be added).

If I sit in VS debug, break at the 'if' statement, and skip over the '.Where' statement, all is fine, the filter is respected.  (In my test, I'm filtering by a single letter in a text column).

However, if I let it roll through, the entire list of eligible questions displays--the filter is (apparently) not run against this data source once we apply the '.Where' clause.

I don't have any theories about why tweaking the results of the IEnumerable list we get back from the service seems like it kills filtering.  Anyone out there in telerik land have/understand this issue?

I think I can work around this pretty easily, but I'd like to understand better why this is going on.

0
golddog
Top achievements
Rank 1
answered on 08 Sep 2008, 09:08 PM
Just in case anybody else looks at this thread...

The problem turns out be using IEnumerable<Question> initially.  While the object I get back from the service is also IQueryable (of course, as its linq to sql generated), as soon as I apply the '.Where' clause, it truly becomes IEnumerable, which radgrid then cannot filter on.

Simple as changing my service, its interface, and my local variable to be IQueryable, and off we went.  Probably could've just made it a var as well, but didn't try that.
Tags
Grid
Asked by
golddog
Top achievements
Rank 1
Answers by
golddog
Top achievements
Rank 1
Share this question
or