Arsip

Archive for April, 2013

ASP.NET MVC JQGrid nuget V.1.1.0

25 April 2013 40 komentar

Update v.1.1.0

  • Add Data Annotation Attribute Approach
  • Fix some minor issue

new Version of Jq.Grid can be access via nuget

https://nuget.org/packages/Jq.Grid/1.1.0

I make more simple coding by using Data Annotation Attribute

Here Sample to use Data Annotation Approach

Controller

using Jq.Grid.Sample.Models;
using System.Linq;
using System.Web.Mvc;

namespace Jq.Grid.Sample.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            JQGridModel<invheader> model = new JQGridModel<invheader>("JsonExample");
            model.Grid.DataUrl = Url.Action("Data");
            return View(model);
        }

        [HttpPost]
        public JsonResult Data()
        {
            JQGridModel<invheader> model = new JQGridModel<invheader>();
            using (DataContext ctx = new DataContext())
            {
                return model.Grid.DataBind(ctx.InvoiceHeader.AsQueryable());
            }
        }
    }
}

Model

using System;
using System.ComponentModel.DataAnnotations;

namespace Jq.Grid.Sample.Models
{
    public class invheader
    {
        [Key, GridColumn(Visible = false)]
        public int id { get; set; }
        [GridColumn(HeaderText = "Invoice Date", DataFormatString = "{0:MM/dd/yyyy}")]
        public DateTime invdate { get; set; }
        [GridColumn(HeaderText = "Customer Name")]
        public string name { get; set; }
        [GridColumn(DataFormatString = "{0:C}")]
        public double amount { get; set; }
        [GridColumn(DataFormatString = "{0:0.00\\%}")]
        public double tax { get; set; }
        [GridColumn(DataFormatString = "{0:C}")]
        public double total { get; set; }
        [GridColumn(DataFormatString = "{0:C}")]
        public string note { get; set; }
        [GridColumn(DataFormatString = "{0:Yes;0;No}")]
        public bool IsPaid { get; set; }
    }
}

View

@model Jq.Grid.JQGridModel<Jq.Grid.Sample.Models.invheader>
@{
    ViewBag.Title = "Index";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>JSON Example</title>

    <!-- The jQuery UI theme that will be used by the grid -->
    @Styles.Render("~/Content/themes/base/css")

    <!-- The jQuery UI theme extension jqGrid needs -->
    <link href="/Content/ui.jqgrid.css" rel="stylesheet" />
</head>
<body>

    <!-- The Partial HTML Grid Table -->
    @Html.Grid().JQGridPartial(Model.Grid)

    <!-- JavaScript at the bottom for fast page loading -->
    @Scripts.Render("~/bundles/jquery")
    <!-- The localization file we need, English in this case -->
    <script src="/Scripts/i18n/grid.locale-en.js"></script>
    <!-- The jqGrid client-side javascript -->
    <script src="/Scripts/jquery.jqGrid.src.js"></script>
    <!-- The Grid Script client-side javascript -->
    @Html.Grid().JQGridScript(Model.Grid)
</body>
</html>

Full sample can be download at github
https://github.com/aiska/Jq.Grid

Kategori:.NET Framework

ASP.NET MVC JQGrid nuget V.1.0.1

23 April 2013 14 komentar

Update v.1.0.1
* Fix DataFormatString render, add boolean string value
* Using Jq.Grid v.4.4.5 (http://www.trirand.com/blog/?p=1047) (i modify some code in js)

This is sample how to use DataFormatString boolean value to string

new JQGridColumn
{
    DataField = "IsDefault",
    HeaderText = "Default",
    DataFormatString = "{0:Yes;0;No}",
    DataType = typeof(bool)
}

You can download update version in nuget
https://nuget.org/packages/Jq.Grid/1.0.1

Next Todo in v.1.1.0
* Using Data Anotation in Column Grid
* Using IFormatter to Convert and Reconvert
* Auto detect DataType in Column Property
* Supporting for Entity Framework 6 (stored procedure) (for insert, update, delete)
* supporting WebApi

I’m very happy to see people downloading the project, and would be glad to get some feedback from you,

So please let me know if you have any problems or other feature requests!

Thanks For your appreciation

Regard,

Aiska Hendra

New Update v.1.1.0

Kategori:.NET Framework