Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Releasing Lib.AspNetCore.Mvc.JqGrid v1.0.0

DZone's Guide to

Releasing Lib.AspNetCore.Mvc.JqGrid v1.0.0

Tired of trying to find the right library of his ASP.NET Core projects, a DZone MVB made his own. Read on to learn more about it!

· Web Dev Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

A long time ago (according to the repository back in 2011) I made my first version of Lib.Web.Mvc public. The initial functionality was a strongly typed helper for jqGrid. In later versions, additional functionalities like Range Requests action result, CSP action attributes and helpers, HSTS attributes or HTTP/2 Server Push with Cache Digest attributes and helpers had been added, but the jqGrid support still remained the biggest one. So when ASP.NET Core was getting closer to RTM, this issue popped up. Now (14 months later) I'm releasing Lib.AspNetCore.Mvc.JqGrid version 1.0.0. As this is not just a port (I took the opportunity to redesign a few things) I've decided to describe the key changes.

Packages Organization

The functionality has been split into four packages:

  • Lib.AspNetCore.Mvc.JqGrid.Infrastructure - Classes, enumerations, and constants representing jqGrid options.
  • Lib.AspNetCore.Mvc.JqGrid.Core - The core serialization and deserialization functionality. If you prefer to write your own JavaScript instead of using strongly typed helpers, but you still want some support on the server side for requests and responses, this is what you want.
  • Lib.AspNetCore.Mvc.JqGrid.DataAnnotations - Custom data annotations which allow for providing additional metadata when working with strongly typed helpers.
  • Lib.AspNetCore.Mvc.JqGrid.Helper - The strongly typed helper (a.k.a. the JavaScript generator).

The split was driven mostly by two use cases which have often been raised. One is separating the (view) models from the rest of the application (for example, independent assembly). The only package needed now in such cases is Lib.AspNetCore.Mvc.JqGrid.DataAnnotations which doesn't have any ties to ASP.NET Core. The second use case is not using the JavaScript generation part, just the support in response and request serialization. That functionality has been separated as well in order to minimize footprint for such scenario.

Usage Basics and Demos

The helper in the version for ASP.NET MVC was an independent class which needed to be initialized (typically in the view) and then could be used to generate the JavaScript and HTML (very similar to System.Web.Helpers.WebGrid). This has been changed, the JavaScript and HTML generation is exposed through IHtmlHelper extensions methods (JqGridTableHtml, JqGridPagerHtml, JqGridHtml, and JqGridJavaScript) which take JqGridOptions instances as parameters. This means that view code can be simplified to this (assuming all needed scripts and styles have been referenced):

@Html.JqGridHtml(gridOptions)
<script>
    $(function () {
        @Html.JqGridJavaScript(gridOptions)
    });
</script>

The JqGridOptions instance can be created anywhere in the application, as it sits in Lib.AspNetCore.Mvc.JqGrid.Infrastructure there is even no reference to ASP.NET Core required. When it comes to the controller code, not much has changed. The Lib.AspNetCore.Mvc.JqGrid.Core provides classes like JqGridRequest, JqGridResponse or JqGridRecord with appropriate binders and converters which are automatically used.

public IActionResult Characters(JqGridRequest request)
{
    ...

    JqGridResponse response = new JqGridResponse()
    {
        ...
    };

    ...

    return new JqGridJsonResult(response);
}

There is a demo project available on GitHub which contains samples of key feature areas with and without helper usage.

Supported Features and a Roadmap

This first version doesn't support all the features which Lib.Web.Mvc did. I've chosen the MVP based on what has been the most common subject for discussions and questions in the past. This gives the following list of areas:

  • Formatters
  • Footer
  • Paging
  • Dynamic scrolling
  • Sorting
  • Single and advanced searching
  • Form and cell editing
  • Grouping
  • Tree grid
  • Subgrids

This is of course not the end. I will soon start setting a roadmap for subsequent releases. This is something that everybody can have their say on by creating or reacting to issues.

In general, I'm open to any form of feedback (tweets, emails, issues, high fives, donations). I will keep working on this project as long as it will have value for anybody and I'll try to answer any questions.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:
web dev ,javascript ,asp.net core

Published at DZone with permission of Tomasz Pęczek, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}