ASP.NET MVC 3.0 Replacing MvcGrid Pager - asp.net-mvc-3

For example if i have an implementation of my own helper and i don't like the default WebGrid pager, how may i replace it?
Is it possible to Replace MvcGrid Pager to change it to my custom one?
I did search and didn't find any thing, only what i think i need to do is to render my one and append it to current WebGrid table as a table footer using jQuery.
Is there any another more simple way of doing this?

You can disable the pager by setting the mode to numeric and setting numericLinksCount to zero. Ex:
<div id="gridSample">
#( var grid = new WebGrid(rowsPerPage: Model.GridRowsPerPage);
grid.Bind(source: Model.ListData,
rowCount: Model.TotalRowCount,
autoSortAndPage: false)
)
#grid.GetHtml(mode: WebGridPagerModes.Numeric, numericLinksCount: 0)
<!--...custom paging here...-->
</div>
Then you're free to render your own paging links using a combination of rows per page and total row count. (Each link should pass the "page" parameter) Easy once you disable the built-in pager... hope that helps.

You can change the Pager Mode on the WebGrid see WebGridPagerModes
Other than this you can style the pager with CSS.

Related

Assembling N-Nested Kendo UI Grid asp.NET MVC 4

I am looking for N level nested child behavior in Kendo UI grid.
so far i have been implementing upto 3-4 level but those grids have to be hard coded in the Code.
Please Guide if somebody has done it dynamic way or generating grid dynamically as child grid
if Possible any alternatives to achieve same.
I hope you guys can help out.
I have edited the Detail Template demo found here: http://demos.telerik.com/kendo-ui/grid/detailtemplate
The fiddle:
http://jsfiddle.net/j5b64/1/
detailRow.find(".orders").kendoGrid({
detailTemplate: kendo.template($("#template").html()),
detailInit: detailInit,
dataSource: {...
Detail rows are not initialized until they are expanded (They don't exist in the DOM). So the call to make the new grid can't happen until we expand the row that will contain it.
Luckily Kendo had provided a 'detailInit' Event that you can plug into and initialize your child grid.
Update for .net binding:
First on your page you will need to define a template. It is important to use a class and not an ID in your template. Your template will be used multiple times and you want to maintain the uniqueness of IDs.
<script type="text/x-kendo-template" id="template">
<div class="orders"></div>
</script>
You will then need to reference that template to be the detail row template for your grid. Here we just need to reference the id of our template above. (you can use .DetailTemplate() to define the template in line, but then it would be harder to use it for later child grids as you would have to parse it out of the server made JS)
#(Html.Kendo().Grid<mySite.ViewModels.GridViewModel>()
.Name("Grid")
.ClientDetailTemplateId("template")
.Columns(columns => .....
Now comes the JS. There is two things we need to do. One is create a reusable initiation function and the other is register this function to be ran on initiation.
In our function we should define a new grid. Again this is done in JS at this point. Theoretically you could define an example grid and look for the server built JQuery that would be its sibling and reuse that for your child grids, but at that point you might as well define your grid using JQuery.
function detailInit(e) {
var detailRow = e.detailRow;
detailRow.find(".orders").kendoGrid({
detailTemplate: kendo.template($("#template").html()),
detailInit: detailInit,
....
Now we need to link up our first grid to use our Initiation function
$(document).ready({
$("#Grid").data("kendoGrid").bind("detailInit", detailInit);
});
I hope this helps.

jqGrid keep current page on refresh

I'm trying to get a jqGrid table to keep its current page on a reload. I've found some samples, but they don't seem to work for me. Here's what I'm trying:
grid.setGridParam({datatype:'json'}).trigger('reloadGrid',[{page:currentPage}]);
It refreshes but always redisplays the first page.
To retain the page on a redraw simply use this:
grid.trigger("reloadGrid",[{current:true}]);
As a matter of interest, you can also get the current page using:
var currentPageVar = grid.getGridParam('page');
Addition:
'grid' is defined thus:
var grid = jQuery("#grid");
Which refers to the ID of the grid table in the HTML.
you can use simply this code:
jQuery("#your_id").trigger("reloadGrid");
You can use
grid.trigger("reloadGrid", {page: currentPage, fromServer: true});
or
grid.trigger("reloadGrid", {current: true, fromServer: true});
in case of usage free jqGrid fork. It's important to use forceClientSorting: true together with loadonce: true.
The reason of the problem, which you describe, is the following: jqGrid can display the second page only if it would make local paging. If you use only loadonce: true then jqGrid display always the first page. More then that, the server have to sort the data returned from the server. The option forceClientSorting: true inform free jqGrid to do filtering, sorting and paging locally after loading the data from the server and before displaying the first (or another) page. The option forceClientSorting: true allows to load relatively large set of data from foreign source (which data one can't control), filter the data locally (to display only required subset of data), sort the result and to display the page of resulting data.
You must be looking for this code
$("#jsGrid").jsGrid("loadData");

jqGrid: Create a custom edit form

I am wanting to customise the edit form in jqGrid so that instead of using the table structured layout provided I would like to use my own custom css structured layout for the form elements. How should I go about modifying the edit form to allow me to use my own custom look?
You can definitely achieve this by jquery ui dialog. However I can not put full code for you but helps you in the steps you have to do.
1 design your custom form whatever CSS and style you want to apply.
Suppose this is youe custome form
<div id="dialog-div">
<input type="text">
</div>
2 on jquery dialog open the dialog on your jqgrid editbutton click
$("#edit").click(function(){
var rowdata = $("#coolGrid").jqGrid('getGridParam','selrow');
if(rowdata){
$("#dialog-div").dialog('open');
var data = $("#coolGrid").jqGrid('getRowData',rowdata);
alert(data);
}
});
by default it will close as-
$("#dialog-div").dialog({
autoOpen: false,
});
Now as you get data in variable you can put in your edit form and of jquery dialog button save it according to your logic.
Hope this helps you.
I would recommend you first of all to read (or at least look thorough) the code of form editing module which implement the part which you want to replace. You will see that it consist from more as 2000 lines of code. If you write "I would like to ..." you should understand the amount of work for implementing what you ask. If you are able to understand the code and if you are able to write your modification of the code even using libraries like jQuery UI then you can decide whether it's worth to invest your time to do the work. The main advantage of using existing solutions is saving of the time. What you get in the way is not perfect, but using existing products you could create your own solutions quickly and with acceptable quality. The way to study existing products which you can use for free seems me more effective as large investments in reinventing the wheel.
http://guriddo.net/?kbe_knowledgebase=using-templates-in-form-editing
Using templates in form editing
As of version 4.8 we support templates in the form editing. This allow to customize the edit form in a way the developer want. To use a template it is needed to set the parameter template in the edit add/or add options of navigator. This can be done in navigator or in the editing method editGridRow :
$("#grid").jqGrid("navGrid",
{add:true, edit:true,...},
{template: "template string for edit",...}
{template: "template string for add",...},
...
);
and in editGridRow method:
$("#grid").jqGrid("editGridRow",
rowid,
{template: "template string",...}
);
To place the CustomerID field in the template the following code string should be inserted in the template string
{CustomerID}
With other words this is the name from colModel put in { }
The usual problem with table layouts is when you have columns with different widths, especially with those very wide.
I solved my problem adding the attr colspan to wide columns in the beforeShowForm event.
for example
"beforeShowForm":function() {
$('#tr_fieldnameasinColModel > td.DataTD').attr('colspan',5);
}
It's not fancy but it worked for me. Perhaps there is a more elegant way to do the same.
I could arrange the fields in several columns without having to make the form extrawide.
When user click on edit button the page navigate to another page, based on Id get the details of a row and you can display the values..
Previous answer of Creating a link in JQGrid solves your problem.

How can I set LabelFor to be hidden

I am able to write in my MVC 3 view:
#Html.TextBoxFor(model => model.Something, new { style = "display: none;" })
But how can I do the same with a LabelFor?
To explain why: I am hiding the label initially but using JQuery to show this label at a later point. I guess I can use JQuery to initially hide it as well, but I would rather do it this way is possible.
Have a look at this post How to specify ID for an Html.LabelFor<> (MVC Razor)
Personally I'd suggest you wrap the TextBox and Label in a containing div, set that element to display:none and have JQuery show/hide the containing div rather than the individual elements.

Jqgrid issue with footer text format

In Jqgrid for some columns I have set as link.
And also for those columns I have set footer (MAX).
But the issue is, configured link is also getting added to the footer value, which is not expected.
Any help is appreciated.
Thanks in advance.
I think the problem is how you add the footer information. If you use footerData you can use false as the last parameter (the format parameter) of footerData. In the case the footer data will not be formatted by the standard formatter of the corresponding column. As the example see the demo.
If you add the data from the server using userdata and use userDataOnFooter jqGrid option the formatter parameter will be alway used as true (see the source code of jqGrid here and here). As a workaround you can remove userDataOnFooter:true setting and add the footer information manually with respect of footerData inside your localComplete event handle:
var myGrid = $("#list"); // your grid
// ...
// inside of localComplete you can add the data
var userData = myGrid.jqGrid("getGridParam","userData");
myGrid.jqGrid("footerData","set",userData,false);

Resources