Skip to main content

How to enable navigation buttons of jQuery grid in mvc3 and assign buttons to specific links?



I have read some topic regarding with my question but there code doesn't work for me. Honestly, I'm not good in jQuery.





I have this working views and controller, but it has a lot disadvantages that is why I switch to using jQuery grid.





Working code (not using jQuery grid):







@using Custom.Helpers

@model IEnumerable<Models.DeviceMVC>



@{

ViewBag.Title = "List";

}



<div id="page-title">

<h2>Device list</h2>

<div id="Optiontab">

@Html.ActionLink("Create New", "Create")

</div>

</div>

<table id="table-list">

<tr>

<th>

Branch

</th>

<th>

Name

</th>

<th>

Login id

</th>

<th>

Serial number

</th>

<th>

Brand

</th>

<th>

Model

</th>

<th></th>

</tr>



@foreach (var item in Model) {

<tr>

<td>

@Html.DisplayFor(modelItem => item.BranchName)

</td>

<td>

@Html.DisplayFor(modelItem => item.Name)

</td>

<td>

@Html.DisplayFor(modelItem => item.LoginID)

</td>

<td>

@Html.DisplayFor(modelItem => item.SerialNum)

</td>

<td>

@Html.DisplayFor(modelItem => item.Brand)

</td>

<td>

@Html.DisplayFor(modelItem => item.Model)

</td>

<td>

@Html.ActionLink("Edit", "Edit", new { id = item.DeviceID, branch = item.BranchName }) |

@Html.ActionLink("Details", "Details", new { id=item.DeviceID })

</td>

</tr>

}

</table>







To resolve the link in side areas, I use this helper:


Helper





To load data:







public ActionResult Index()

{

IDeviceComponentMVC mvc = new DeviceComponentMVC();

return View(mvc.RetrieveAllDevices());

}







Now in jQuery (View part):







<script type="text/javascript">

jQuery(document).ready(function () {

jQuery("#list").jqGrid({

url: '@Url.Content("~/Device/LoadDevice")',

datatype: 'json',

mtype: 'POST',

colNames: ['Branch', 'Name', 'Username', 'Serial', 'Brand', 'Model'],

colModel: [

{ name: 'Branch', index: 'Branch', width: 136, align: 'Branch', sortable: false },

{ name: 'Name', index: 'Name', width: 136, align: 'Name' },

{ name: 'LoginID', index: 'LoginID', width: 136, align: 'LoginID' },

{ name: 'SerialNum', index: 'SerialNum', width: 100, align: 'SerialNum' },

{ name: 'Brand', index: 'Brand', width: 136, align: 'Brand' },

{ name: 'Model', index: 'Model', width: 136, align: 'Model' }

],

pager: jQuery('#pager'),

rowNum: 5,

rowList: [10, 50, 100, 150, 250, 300, 350, 400, 500],

sortname: 'Name',

sortorder: "desc",

viewrecords: true,

imgpath: '',

caption: 'Device list'

})

});



</script>

<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>

<div id="pager" class="scroll" style="text-align:center; padding:50px;"></div>







Controller part:







public JsonResult LoadDevice(string sidx, string sord, int page, int rows)

{

using (DBase db = new DBase())

{

var context = db;

int pageIndex = Convert.ToInt32(page) - 1;

int pageSize = rows;

int totalRecords = context.devices.Count();

int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);



var devices = context.devices.OrderBy("it." + sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize);



var sorted = (from item in devices

select new

{

i = item.DeviceID,

cell = new List<string> { item.branch.Name, item.Name, item.LoginID, item.SerialNum, item.Brand, item.Model }

}).ToArray();



var jsonData = new

{

total = totalPages,

page,

records = totalRecords,

rows = sorted

};

return Json(jsonData);

}

}







Now my very goal is to put navigation buttons like this:





enter image description here





But these button should have specific link. The link like what my first view (without jQuery grid) does have.





Currently I have:





enter image description here





Hope someone could help. Thanks a lot!


Comments

  1. You miss one line in your script. Append this to your script, to make the last lines look like this:

    caption: 'Device list'
    }).navGrid("#pager, { add: false, edit: false, del: false }


    See http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator for all the details of this function.

    ReplyDelete
  2. I found the best answer here:

    http://www.trirand.com/blog/jqgrid/jqgrid.html#

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 1 Final Exam 2011 latest (hot hot hot)

  Hi! I have been posted content of ccna1 final exam (latest and only question.) I will post the answer and insert image on sunday. If you care, please subscribe your email an become a first person have full test content. Subcribe now  Some question  have not content because this question have images content. So that can you wait for me? SUNDAY 1. A user sees the command prompt: Router(config-if)# . What task can be performed at this mode? Reload the device. Perform basic tests. Configure individual interfaces. Configure individual terminal lines. 2. Refer to the exhibit. Host A attempts to establish a TCP/IP session with host C. During this attempt, a frame was captured with the source MAC address 0050.7320.D632 and the destination MAC address 0030.8517.44C4. The packet inside the captured frame has an IP source address 192.168.7.5, and the destination IP address is 192.168.219.24. At which point in the network was this packet captured? leaving host A leaving ATL leaving...