Git Product home page Git Product logo

asp-net-mvc-scheduler-use-checkboxlist-to-filter-resources's Introduction

Scheduler for ASP.NET MVC - How to use CheckBoxList to filter resources

This is a counterpart of the How to filter resources in ASPxScheduler via ASPxListBox code example but for ASP.NET MVC platform.

Overview

As a starting point, we are using the data-bound Scheduler in the partial view (see Note section in the Callback-Based Functionality help article). You can find a similar logic in Lesson 2 - Implement Insert-Update-Delete Appointment Functionality. But our code is more extensible and reliable for the following reason.

We use the SchedulerHelper class to initialize Scheduler settings for both view and controller. This allows us to implement a reliable solution according to the Lesson 3 - Use Scheduler in Complex Views. This is preferable implementation, which should operate correctly in any possible scenarios.

It is not necessary to isolate CheckBoxList in a partial view because it is not operating in callback mode. Thus, we place it in the main view:

@model SchedulerFilterResourcesDataLevelMvc.Models.SchedulerDataObject

<script type="text/javascript">
// <![CDATA[
    function OnSelectedIndexChanged(s, e) {
        scheduler.PerformCallback();
    }
    function OnBeginCallback(s, e) {
        e.customArgs['SelectedResources'] = cbResources.GetSelectedValues().join(',');
    }
// ]]>
</script>

<table>
    <tr>
        <td valign="top">
            @Html.DevExpress().CheckBoxList(settings => {
                settings.Name = "cbResources";
                settings.Width = System.Web.UI.WebControls.Unit.Pixel(200);
                settings.Properties.ClientSideEvents.SelectedIndexChanged = "OnSelectedIndexChanged";
                settings.Properties.ValueField = "ID";
                settings.Properties.TextField = "Model";
            }).BindList(Model.Resources).GetHtml()
        </td>
        <td>
            @Html.Partial("SchedulerPartial", Model)
        </td>
    </tr>
</table>

The OnBeginCallback function name is assigned to the settings.ClientSideEvents.BeginCallback attribute of the Scheduler settings initialized in the SchedulerHelper class. Thus, this function is called before callback occurs. We pass parameters to the corresponding controller's action in this function as described in thePassing Values to Controller Action Through Callbacks help topic. This action is defined as follows:

public ActionResult SchedulerPartial() {
    return PartialView("SchedulerPartial", SchedulerDataHelper.GetDataObject(GetSelectedResourceIds()));
}
...
List<int> GetSelectedResourceIds() {
    string request = (Request.Params["SelectedResources"] != null) ? (Request.Params["SelectedResources"]) : string.Empty;
    return (request != string.Empty) ? request.Split(',').Select(n => Convert.ToInt32(n)).ToList<int>() : new List<int>();
}

The SchedulerDataHelper.GetDataObject() method is implemented so that the returned object resources are filtered by a list of Ids passed to this method. Note that we use this method in the EditAppointment action either.

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

asp-net-mvc-scheduler-use-checkboxlist-to-filter-resources's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Watchers

Paul Usher avatar James Cloos avatar Alexander Bulychev avatar konyukhov.sergey avatar  avatar Don Wibier avatar zhavoronkov.evgeny avatar Maxim Litvinov avatar  avatar Julian M Bucknall avatar Alexey Serov avatar Andrey Belym avatar Mary Sammal avatar Mark Miller avatar  avatar Barkovskiy Maksim avatar Mikhail Preyskurantov avatar  avatar Christian Santos avatar  avatar  avatar  avatar  avatar Helen Wilde avatar Anthony Sam avatar A'Lex'ander avatar  avatar  avatar  avatar Alexander Russkov avatar  avatar  avatar  avatar  avatar Natalya Shtikel avatar EugeniyKiyashko avatar Viktor Shchelkunov avatar  avatar Alexander Zelevinskiy avatar Elena Soloveva avatar  avatar 71A1den avatar Oleg Luchnikov avatar  avatar Nick Mitrokhin avatar  avatar Jane Ryzhikova avatar  avatar Natalya Rodionova avatar Sergey Nakhankov avatar volvl avatar Max Erokhin avatar Roman Rodin avatar Serghey avatar Natalya Senichkina avatar  avatar

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.