Esempio n. 1
0
        public virtual void Filter(Com.Evrencoskun.Tableview.Filter.Filter filter)
        {
            if (originalCellDataStore == null || originalRowDataStore == null)
            {
                return;
            }

            originalCellData = new AList <IList <ICell> >(originalCellDataStore);
            originalRowData  = new AList <IRowHeader>(originalRowDataStore);
            filteredCellList = new AList <IList <ICell> >();
            filteredRowList  = new AList <IRowHeader>();
            if (filter.GetFilterItems().Count == 0)
            {
                filteredCellList = new AList <IList <ICell> >(originalCellDataStore);
                filteredRowList  = new AList <IRowHeader>(originalRowDataStore);
                DispatchFilterClearedToListeners(originalCellDataStore, originalRowDataStore);
            }
            else
            {
                for (int x = 0; x < filter.GetFilterItems().Count;)
                {
                    FilterItem filterItem = filter.GetFilterItems()[x];
                    if (filterItem.GetFilterType().Equals(FilterType.All))
                    {
                        foreach (IList <ICell> itemsList in originalCellData)
                        {
                            foreach (ICell item in itemsList)
                            {
                                if (((IFilterableModel)item).GetFilterableKeyword().ToLower()
                                    .Contains(filterItem.GetFilter().ToLower()))
                                {
                                    filteredCellList.Add(itemsList);
                                    filteredRowList.Add(originalRowData[filteredCellList.IndexOf(itemsList)]);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (IList <ICell> itemsList in originalCellData)
                        {
                            if (((IFilterableModel)itemsList[filterItem.GetColumn()]).GetFilterableKeyword().ToLower()
                                .Contains(filterItem.GetFilter().ToLower()))
                            {
                                filteredCellList.Add(itemsList);
                                filteredRowList.Add(originalRowData[filteredCellList.IndexOf(itemsList)]);
                            }
                        }
                    }

                    // If this is the last filter to be processed, the filtered lists will not be cleared.
                    if (++x < filter.GetFilterItems().Count)
                    {
                        originalCellData = new AList <IList <ICell> >(filteredCellList);
                        originalRowData  = new AList <IRowHeader>(filteredRowList);
                        filteredCellList.Clear();
                        filteredRowList.Clear();
                    }
                }
            }

            // Sets the filtered data to the TableView.
            mRowHeaderRecyclerViewAdapter.SetItems(filteredRowList, true);
            mCellRecyclerViewAdapter.SetItems((IList <IList <ICell> >)filteredCellList, true);
            // Tells the listeners that the TableView is filtered.
            DispatchFilterChangedToListeners(filteredCellList, filteredRowList);
        }