Monday, 9 September 2013

KnockOut KoGrid in MVC4

It is the highlt performanced knockout datagrid.The main benefits we get out of KoGrid is the ability to define custom row and cell templates.
It's working in all main stream browsers.Here i am going to show a basic example of KoGrid. Through NuGet , we can install Knockout and KoGrid in our application.
After I created a javascript file for  View Model
function viewModel() {

    var self = this;
    self.items = ko.observableArray([{ firstName: "Eric", lastName: "Sam", mail: "",phno:"1212121" },
    { firstName: "Manuel", lastName: "Dan", mail: "", phno: "234232" },
    { firstName: "Allen", lastName: "Ken", mail: "", phno: "564523" },
    { firstName: "Joe", lastName: "George", mail: "", phno: "46545435" },
     { firstName: "aki", lastName: "Ken", mail: "", phno: "32267565"}]);

$(document).ready(function () {
    ko.applyBindings(new viewModel(), document.getElementById('disp'));

After that i create a bundle for KoGrid , Knockout and MyGrid
bundles.Add(new ScriptBundle("~/bundles/myBundle").Include(

After that added KoGrid css into Style Bundle.
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css","~/Content/KoGrid.css"));

<div id="disp" >
<div id="grid" style="height: 200px;"  data-bind="koGrid: { data: items,afterSelectionChange: function () { return true; },
                          columnDefs: [{ field: 'firstName', displayName: 'First Name',width:'300'},
                                       { field: 'lastName', displayName: 'Last Name',width:'300' },
                                       { field: 'phno',displayName: 'PhNo' ,width:'300'},
                                       { field: 'mail',displayName: 'MailID',width:'401'}],
                                       autogenerateColumns: false, 
                                       isMultiSelect: true,
                                       showFilter: true,
                                       showColumnMenu: false

KoGrid is very configurable. Here  We will get More configuration Information.
Here I used a sample array. We can use json array for data in KoGrid.KoGrid have inbuilt functionality like sorting ,paging and search.

No comments:

Post a Comment