diff --git a/GridMvc.Site/Scripts/gridmvc.customwidgets.js b/GridMvc.Site/Scripts/gridmvc.customwidgets.js index 86f6443..c3edda4 100644 --- a/GridMvc.Site/Scripts/gridmvc.customwidgets.js +++ b/GridMvc.Site/Scripts/gridmvc.customwidgets.js @@ -10,6 +10,7 @@ * * For more documentation see: http://gridmvc.codeplex.com/documentation */ +//Updated by Aman Sharma (http://HarvestingClouds.com) /*** * CustomersFilterWidget - Provides filter user interface for customer name column in this project @@ -58,8 +59,10 @@ function CustomersFilterWidget() { this.renderWidget = function () { var html = '

This is custom filter widget demo.

\

Select customer to filter:

\ - '; +

\ +
\ + \ +
'; this.container.append(html); }; /*** @@ -77,7 +80,7 @@ function CustomersFilterWidget() { this.fillCustomers = function (items) { var customerList = this.container.find(".customerslist"); for (var i = 0; i < items.length; i++) { - customerList.append(''); + customerList.append(' -1 ? 'checked="checked"' : '') + ' value="' + items[i] + '">' + items[i] + '
'); } }; /*** @@ -86,13 +89,44 @@ function CustomersFilterWidget() { this.registerEvents = function () { //get list with customers var customerList = this.container.find(".customerslist"); + //get apply button from: + var applyBtn = this.container.find(".grid-apply"); //save current context: var $context = this; //register onclick event handler - customerList.change(function () { + applyBtn.click(function () { + //get selected filter type: + //var type = $context.container.find(".grid-filter-type").val(); + var type = 1; + //get filter value: + //var value = $context.container.find(".grid-filter-input").val(); + var value = ""; + + $('.customerslist input:checked').each(function (index, element) { + if (index == 0) { + value += element.value; + } + else { + value += "|" + element.value; + } + }); + + //invoke callback with selected filter values: - var values = [{ filterValue: $(this).val(), filterType: 1 /* Equals */ }]; - $context.cb(values); + var filterValues = [{ filterType: type, filterValue: value }]; + $context.cb(filterValues); + }); + //register onclick event handler + //customerList.change(function () { + ////invoke callback with selected filter values: + //var values = [{ filterValue: $(this).val(), filterType: 1 /* Equals */ }]; + //$context.cb(values); + //}); + + //register onEnter event for filter text box: + this.container.find(".grid-filter-input").keyup(function (event) { + if (event.keyCode == 13) { applyBtn.click(); } + if (event.keyCode == 27) { GridMvc.closeOpenedPopups(); } }); }; diff --git a/GridMvc/Filtering/DefaultColumnFilter.cs b/GridMvc/Filtering/DefaultColumnFilter.cs index f78659d..87d3fdd 100644 --- a/GridMvc/Filtering/DefaultColumnFilter.cs +++ b/GridMvc/Filtering/DefaultColumnFilter.cs @@ -52,9 +52,24 @@ private Expression> GetFilterExpression(PropertyInfo pi, ColumnFil ? Expression.Property(_expression.Body, pi.PropertyType.GetProperty("Value")) : _expression.Body; - Expression binaryExpression = filterType.GetFilterExpression(firstExpr, value.FilterValue, value.FilterType); - if (binaryExpression == null) return null; + Expression binaryExpression; + if (value.FilterValue.Contains("|")) + { + var filterValues = value.FilterValue.Split('|'); + binaryExpression = filterType.GetFilterExpression(firstExpr, filterValues[0], value.FilterType); + for (int i = 1; i < filterValues.Count(); i++) + { + Expression tempExpr = filterType.GetFilterExpression(firstExpr, filterValues[i], value.FilterType); + binaryExpression = Expression.Or(tempExpr, binaryExpression); + } + } + else + { + binaryExpression = filterType.GetFilterExpression(firstExpr, value.FilterValue, value.FilterType); + } + + if (binaryExpression == null) return null; if (targetType == typeof (string)) { //check for strings, they may be NULL diff --git a/GridMvc/GridMvc.csproj b/GridMvc/GridMvc.csproj index 80ac5d8..2006805 100644 --- a/GridMvc/GridMvc.csproj +++ b/GridMvc/GridMvc.csproj @@ -48,8 +48,8 @@ - - + +