All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:
/// <summary>
/// Represents a filtercell that will clear all filters.
/// </summary>
public
class
ClearAllFiltersCell : GridFilterCellElement
{
private
RadButtonElement btnClearAll;
/// Initializes a new instance of the <see cref="CheckBoxHeaderCell"/> class.
/// <param name="column"></param>
/// <param name="row"></param>
ClearAllFiltersCell(GridViewDataColumn column, GridRowElement row)
:
base
(column, row)
}
/// Creates the child elements.
protected
override
void
CreateChildElements()
// The clear all button
btnClearAll =
new
RadButtonElement();
btnClearAll.Text =
"Clear All"
;
btnClearAll.Click +=
EventHandler(btnClearAll_Click);
// Create the child elements, otherwise the necessary elements are not in place
.CreateChildElements();
// Clear all children
this
.Children.Clear();
// Add our button
.Children.Add(btnClearAll);
/// Adds the editor.
/// <param name="editor">The editor.</param>
AddEditor(IInputEditor editor)
// Override this and leave it blank. Clicking on the clear all button will
// still trigger adding an editor and we dont' want that.
/// Arranges the override.
/// <param name="finalSize">The final size.</param>
/// <returns></returns>
SizeF ArrangeOverride(SizeF finalSize)
// This will correctly set the cell size so the clear all button is centered in the cell
SizeF size =
.ArrangeOverride(finalSize);
RectangleF rect = GetClientRectangle(finalSize);
.btnClearAll.Arrange(
RectangleF((finalSize.Width -
.btnClearAll.DesiredSize.Width) / 2, (rect.Height - 20) / 2, 20, 20));
return
size;
/// Handles the Click event of the btnClearAll control.
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
btnClearAll_Click(
object
sender, EventArgs e)
// Clear all the filter decriptors
.GridControl.FilterDescriptors.Clear();
radGridView1_CreateCell(
sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
if
(e.Row
is
GridFilterRowElement)
// Replace "Id" with the column name where you want the Clear All button
(e.Column == radGridView1.Columns[
"Id"
])
e.CellElement =
ClearAllFiltersCell((GridViewDataColumn)e.Column, e.Row);