Coder Social home page Coder Social logo

devexpress-examples / asp-net-mvc-grid-filter-dates-by-month Goto Github PK

View Code? Open in Web Editor NEW
0.0 55.0 1.0 474 KB

Create an unbound column, populate it with data from a data source, and customize header filter items.

License: Other

C# 8.77% JavaScript 85.50% HTML 5.57% ASP.NET 0.16%
dotnet mvc-gridview asp-net-mvc header-filter unbound-column

asp-net-mvc-grid-filter-dates-by-month's Introduction

Grid View for ASP.NET MVC - How to filter dates by month

This example demonstrates how to create an unbound column, populate it with data from a data source, and customize header filter items.

Filter Dates by Month

Overview

Follow the steps below to filter dates by month:

  1. Add an unbound column that stores month numbers. To enable this behavior, set the column's UnboundType to Integer.

    settings.Columns.Add(column => {
        column.FieldName = "Month";
        column.ColumnType = MVCxGridViewColumnType.DateEdit;
        column.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
        column.SettingsHeaderFilter.Mode = GridHeaderFilterMode.CheckedList;
    })
  2. Handle the grid's CustomUnboundColumnData event. In the handler, get date values from the specified bound column and populate the unbound column cells with month numbers.

    settings.CustomUnboundColumnData = (sender, e) => {
        if (e.Column.FieldName == "Month") {
            DateTime value = (DateTime)e.GetListSourceFieldValue("C5");
            e.Value = value.Month;
        }
    };
  3. To display full dates in the unbound column, handle the grid's CustomColumnDisplayText event and specify its DisplayText argument property.

    settings.CustomColumnDisplayText = (sender, e) => {
        if (e.Column.FieldName == "Month") {
            DateTime realValue = ((DateTime)e.GetFieldValue("C5"));
            e.DisplayText = realValue.ToString("dd MMM yyyy");
        }
    };
  4. Handle the grid's HeaderFilterFillItems event to add custom header filter items based specified by the month number.

    settings.HeaderFilterFillItems = (sender, e) => {
        if (e.Column.FieldName == "Month") {
            e.Values.Clear();
            e.AddValue("January", "1");
            e.AddValue("February", "2");
            e.AddValue("March", "3");
            e.AddValue("April", "4");
            e.AddValue("May", "5");
            e.AddValue("June", "6");
            e.AddValue("July", "7");
            e.AddValue("August", "8");
            e.AddValue("September", "9");
            e.AddValue("October", "10");
            e.AddValue("November", "11");
            e.AddValue("December", "12");
        }
    };

Files to Review

Documentation

asp-net-mvc-grid-filter-dates-by-month's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

elenapeskova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.