Please, select a language:



jqGrid for ASP.NET Core comes with a large number of predefined language packs and settings for almost all popular languages. They are located in the installation package, in the /js/i18n folder. Lnaguage packs are in the form of javascript files, containing definitions for all strings in the grid that can be localized - this includes messages, captions, paging information, search/add/delete dialog labels, etc.

In order to use a particular language pack, you need to include the javascript language pack to the head of your page, after the jQuery library reference (since language packs depend on jQuery) and before referencing the jqGrid javascript file (since it is dependent on the language pack).

jqGrid can change its locale on the client-side as well, without trip to the server. To do so, use the following syntax:
$.jgrid.setRegional('GridID',{regional: lng});

where "lng" is the locale you wish to use - e.g. "en", "de", "kr", "bg", etc.
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using Trirand.Web.Core;

namespace CoreDemo.Models
{
    public class OrdersJqGridModel
    {
        public CoreGrid OrdersGrid { get; set; }

        public OrdersJqGridModel(HttpContext context)
        {
            OrdersGrid = new CoreGrid(context)
            {
                Columns = new List<CoreColumn>()
                {
                    new CoreColumn
                    {
                        // Always set PrimaryKey for Add,Edit,Delete operations
                        // If not set, the first column will be assumed as primary key
                        DataField = "OrderId",
                        PrimaryKey = true,
                        Editable = false,
                        Width = 50,
                        DataType = typeof(int)                        
                    },
                    new CoreColumn
                    {
                        DataField = "CustomerId",
                        Editable = true,
                        Width = 100,
                        DataType = typeof(string),

                    },
                    new CoreColumn
                    {
                        DataField = "OrderDate",
                        Editable = true,
                        Width = 100,
                        DataFormatString = "{0:yyyy/MM/dd}",
                        DataType = typeof(DateTime)
                    },
                    new CoreColumn
                    {
                        DataField = "Freight",
                        Editable = true,
                        Width = 75,
                        DataType = typeof(double)
                    },
                    new CoreColumn
                    {
                        DataField = "ShipName",
                        Editable =  true,
                        Width = 150,
                        DataType = typeof(string)
                    }
                },

                Width = "640",
                Height = "250",
                
                ToolBarSettings = new ToolBarSettings
                {
                    ShowRefreshButton = true
                }
            };  
        }        
    }
}
@model CoreDemo.Models.OrdersJqGridModel
@using Trirand.Web.Core

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <title>jqGrid for ASP.NET Core - Localization</title>    
    <!-- jQuery runtime minified -->
    <script src="~/js/jquery-3.2.1.min.js" type="text/javascript"></script>
    <!-- The jqGrid localization file we need, English in this case -->
    <script type="text/javascript" src="~/js/trirand/i18n/@ViewData["localeScript"]"></script>
    <!-- The jqGrid client-side javascript -->
    <script type="text/javascript" src="/js/trirand/coregrid.min.js"></script>
    <!-- The jQuery UI theme that will be used by the grid. -->
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.12.1/themes/redmond/jquery-ui.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->    
    <link rel="stylesheet" type="text/css" href="~/css/trirand/coregrid.css" />
</head>
<body>    
    <div>           
        @{ Html.BeginForm("functionalitylocalization", "grid"); }
        <span style="font-family:Verdana">Please, select a language:</span> @Html.DropDownList("locale", ViewData["localesList"] as SelectList, new { onchange="this.form.submit();" })                   
        @{ Html.EndForm(); }
        <br />
        @Html.Trirand().CoreGrid(Model.OrdersGrid, "CoreGrid")
    </div>
    <br /><br />
    <div>
         @await Component.InvokeAsync("CodeTabs", new { product = "grid", example = "functionalitylocalization" })        
    </div>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.AspNetCore.Mvc;
using CoreDemo.Models;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace CoreDemo.Controllers.Grid
{
    public partial class GridController : Controller
    {
        // This is the default action for the View. Use it to setup your grid Model.
        public ActionResult FunctionalityLocalization(string locale)
        {
            string jsLocale = locale ?? "grid.locale-en.js";

            ViewData["localesList"] = GetLocales(jsLocale);
            ViewData["localeScript"] = jsLocale;

            // Pass the custmomized grid model to the View
            return View(GetGridModel());
        }        

        // This method is called when the grid requests data. You can choose any method to call
        // by setting the CoreGrid.DataUrl property
        public JsonResult LocalizationDataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel = GetGridModel();
            var northWindModel = new NorthWind();

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET Core automatically takes care of paging, sorting, filtering/searching, etc
            return gridModel.OrdersGrid.DataBind(northWindModel.Orders);
        }

        private OrdersJqGridModel GetGridModel()
        {
            // Get the model (setup) of the grid defined in the /Models folder.
            var gridModel = new OrdersJqGridModel(HttpContext);

            // Customize/change some of the default settings for this model
            // ID is a mandatory field. Must by unique if you have several grids on one page.
            gridModel.OrdersGrid.ID = "OrdersGrid";
            // Setting the DataUrl to an action (method) in the controller is required.
            // This action will return the data needed by the grid
            gridModel.OrdersGrid.DataUrl = Url.Action("LocalizationDataRequested");

            return gridModel;
        }

        public SelectList GetLocales(string selectedValue)
        {
            List<SelectListItem> countries = new List<SelectListItem>();
            countries.Add(new SelectListItem { Text = "English", Value = "grid.locale-en.js" });
            countries.Add(new SelectListItem { Text = "German", Value = "grid.locale-de.js" });
            countries.Add(new SelectListItem { Text = "French", Value = "grid.locale-fr.js" });
            countries.Add(new SelectListItem { Text = "Spanish", Value = "grid.locale-sp.js" });
            countries.Add(new SelectListItem { Text = "Italian", Value = "grid.locale-it.js" });
            countries.Add(new SelectListItem { Text = "Dutch", Value = "grid.locale-nl.js" });
            countries.Add(new SelectListItem { Text = "Norwegian", Value = "grid.locale-no.js" });
            countries.Add(new SelectListItem { Text = "Finish", Value = "grid.locale-fi.js" });
            countries.Add(new SelectListItem { Text = "Hebrew", Value = "grid.locale-he.js" });
            countries.Add(new SelectListItem { Text = "Japanese", Value = "grid.locale-jp.js" });
            countries.Add(new SelectListItem { Text = "Portuguese", Value = "grid.locale-pt.js" });
            countries.Add(new SelectListItem { Text = "Brasilian-Portuguese", Value = "grid.locale-pt-br.js" });
            countries.Add(new SelectListItem { Text = "Russian", Value = "grid.locale-ru.js" });
            countries.Add(new SelectListItem { Text = "Romanian", Value = "grid.locale-ro.js" });
            countries.Add(new SelectListItem { Text = "Polish", Value = "grid.locale-pl.js" });
            countries.Add(new SelectListItem { Text = "Czech", Value = "grid.locale-cs.js" });
            countries.Add(new SelectListItem { Text = "Greek", Value = "grid.locale-el.js" });
            countries.Add(new SelectListItem { Text = "Persian", Value = "grid.locale-fa.js" });
            countries.Add(new SelectListItem { Text = "Icelandic", Value = "grid.locale-is.js" });
            countries.Add(new SelectListItem { Text = "Swedish", Value = "grid.locale-sv.js" });
            countries.Add(new SelectListItem { Text = "Turkish", Value = "grid.locale-tr.js" });
            countries.Add(new SelectListItem { Text = "Ukrainian", Value = "grid.locale-ua.js" });
            countries.Add(new SelectListItem { Text = "Catalan", Value = "grid.locale-cat.js" });
            countries.Add(new SelectListItem { Text = "Bulgarian", Value = "grid.locale-bg.js" });

            return new SelectList(countries, "Value", "Text", selectedValue);
        }

    }
}
Switch theme:


Theming is based on the very popular jQuery ThemeRoller standard. This is the same theming mechanism used by jQuery UI and is now a de-facto standard for jQuery based components. The benefits of using ThemeRoller are huge. We can offer a big set of ready to use themes created by professional designers, including Windows-like themes (Redmond), Apple-like theme (Cupertino), etc. In addition to that any jQuery UI controls on the same page will pick the same theme.

Last, but not least, you can always roll your own ThemeRoller theme, using the superb Theme Editor

To use a theme, simply reference 2 Css files in your Html <head> section - the ThemeRoller theme you wish to use, and the jqGrid own ThemeRoller Css file. For example (Redmond theme):

<link rel="stylesheet" type="text/css" media="screen" href="/themes/redmond/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/themes/coregrid.css" />