Jqgrid issue with footer text format - jqgrid

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);

Related

Select2 with ajax option

I have been using selec2 version 4 with ajax option.
And I want to set a selected value, as recommended in the guideline, by adding new Option element.
A problem I have is that I do not know when to add the new option because the event select2-loaded does not seem to exist in the latest version of select 2.
Can you please let me know in what way I can know the moment when data has finished loading from the server and has finished setting up, so I can add a new option to it?
Thank you.
The Option element you mention is created by calling the Option() constructor which then constructs a HTMLOptionElement. So basically you are just adding to your DOM and don't need to do it in any select2 event. Instead just do it on document load.
Here's a very basic example of what it could look like:
$(function () {
$('#element-to-select').select2();
var option = new Option('text', 'value', true, true);
$('#element-to-select').append(option).trigger('change');
}
Note that we are calling .trigger('change') to report the change to select2 as documented here.

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.

jqGrid setting zIndex for alertmod

I have successfully increased the zIndex for edit,add,del and search options but alertmod is still at z-index 950 making it always behind parent modal.
alertmod is the warning message when click edit or delete without selecting any row. Is there a way to change the zIndex for alertmod?
new code but still not working... did I place it in wrong order
$("#list-employees-grid").jqGrid('navGrid',"#list-employees-pager",{alertzIndex:3234},
{edit:true,add:false,del:true,search:true,},
{zIndex:1234}, //option for edit
{zIndex:2234}, // for add
{zIndex:3234}, // del
{zIndex:4234, multipleSearch:true, multipleGroup:true} // search
);
There are some cases where the "alertmod" can be created. For example if you mean alerts from the navGrid you can use alertzIndex option which is currently just not documented in the list of navGrid parameters. Nevertheless you can use for example the following options used by alert dialogs: alertcap, alerttop, alertleft,alertwidth,alertheight,closeOnEscape, alertzIndex. See the line of code for details.
For example you can set default value for alertzIndex by
$.extend($.jgrid.nav, {alertzIndex: 1005});
UPDATED: I posted the feature request which could solve the problem with the options of alert dialog in the common case.
UPDATED 2: The feature request is already implemented in the jqGrid code on github (see here). So in the next version (the next after 4.4.0) one will be able to use
$.extend($.jgrid.jqModal, {zIndex: 1005});
to set default z-Index for all alert messages shown by jqGrid.
Yes, there is an alertzIndex option that can be used to specify a custom zIndex. For example:
jQuery("#grid_id").jqGrid({
...
pager : '#gridpager',
...
}).jqGrid('navGrid', '#gridpager', {alertzIndex: customZIndex, ...});
This option is missing from the jqGrid Navigator documentation and should probably have an entry in the Parameters section. You can see all of the possible options in the source code if you look at grid.formedit.js and browse to the navGrid function definition at line 1702.
Does that help?

Create base jqgrid

I have a website with several views, and most of them have a jqGrid on them.
I'd like to set some base options on all my jqgrids. For example, I'd like the view option to always be set to true, and the search option to always be set to false.
Additionally, there are several that I'd like to have the same button labels.
Is there any way to do this with a jqGrid?
Look at the answer which shows how to set default settings jQuery.jgrid.nav. In your case it would be
jQuery.extend(jQuery.jgrid.nav,
{search:false,view:true, viewtext:"View label", viewtitle:"View tooltip"}
);
Other default settings you can change in the same way using jQuery.jgrid.del, jQuery.jgrid.view and of course jQuery.jgrid.defaults.
You don't need to place the code inside of jQuery(document).ready(function() {/**/});. It is enough just ecxecute the code like jQuery.extend(jQuery.jgrid.nav, {search:false,view:true}); inside a JavaScript file loaded after the jquery.jqGrid.min.js.
You could add an additional script tag to your HTML that references a JS file with some base configuration stuff for the grid in a $().ready(function() {}); block.
You could also create a base configuration function or variable that you store in that external JS, and reference that configuration on each view page.
I would prefer to write the base function, and not the ready event handler as the ready handler will NOT run at a predictable time. You won't know if it properly ran before your jqGrid configure function ran.

jqgrid add link to column headers

I'm using jqgrid to create a grid. I have looked but can't seem to find a solution. I'm trying to add links to the column headers.
Any help appreciated.
Thanks
Use jQuery to bind your click event:
jQuery(document).ready(function() {
$("#jqgh_colName").click(function() {
alert('jqgh_colName clicked');
});
});
jqGrid creates the column header names using names in the colName list. So you can try putting the markup directly in this list during grid initialization:
colNames:['Test', 'Column 2', ... ],
I have not tested this, so YMMV. Also keep in mind there may be usability issues - a user is probably going to expect that clicking on a header would sort the column.
Here you can find the exact options.
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter

Resources