The width parameter of the jqGrid edit modal breaks the other parameters - jqgrid

When I add width to the edit modal in jqGrid, the parameters after it (i.e., add:false, closeAfterEdit: true, etc.) stop working. I've tried it in different places, and it doesn't work.
jQuery("#prodgrid").jqGrid('navGrid', '#pager', {width: 1000},{edit: true, add: false, del: false, search: false}, {closeAfterEdit: true}, {closeAfterAdd: true});
FYI:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.8.0/js/i18n/grid.locale-en.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.8.0/js/jquery.jqgrid.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>

You use wrong options of navGrid. If you examine the documentation you will see that the position of the parameters which you use is wrong. The correct will be
$("#prodgrid").jqGrid('navGrid', '#pager',
{add: false, del: false, search: false},
{closeAfterEdit: true, width: 1000},
{closeAfterAdd: true, width: 1000});
(you can skip edit: true because it's already default value).
I see that you use free jqGrid. It makes specifying of jqGrid options easier. First of all you can skip '#pager'. In the case jqGrid will just use the pager which you already specified during creating of the grid. Seconds you can specify page: true in the option of the grid instead of usage pager: '#pager'. You will don't need to create empty <div id="pager"></div> in the case. By usage page: true free jqGrid will create the corresponding div automatically. Moreover the options of 'navGrid' are divided in independent parts: the navGrid option {edit: true, add: false, del: false, search: false} and the options of form editing: {closeAfterEdit: true, width: 1000} and {closeAfterAdd: true, width: 1000}. Free jqGrid allows to specify the options directly during creating the grid and then use simplified form of the call of navGrid:
$("#prodgrid").jqGrid({
// here there are all other standard option which you already use
pager: true,
navOptions: {add: false, del: false, search: false},
formEditing: {closeAfterEdit: true, closeAfterAdd: true, width: 1000}
}).jqGrid("navGrid");
You can read more about the style of coding the option of jqGrid here. I personally like much more named parameter as positioned parameter because everybody can better read the code.

Related

jqGrid Frozen Columns in a Subgrid

I know that frozen columns does not work if Sub-Grid is enabled from http://www.trirand.com/jqgridwiki/doku.php?id=wiki:frozencolumns.
My understanding is that frozen does not work in the parent grid but it should work in the Sub-grid?
But when I try frozen column in sub grid it does not work? Does it mean frozen columns does not work in both the parent and Sub-grid.
If you use subgrid as grid then jqGrid just creates empty <div> in the "subgrid row" where any information can be placed. So you can create for example new grid with any features in the div. You can create grid with frozen columns of cause.
I created the demo for you by modifying the demo from an old answer. The results looks like below
I marked the header of frozen columns using CSS
.ui-jqgrid .frozen-div .ui-th-column { background: #f0dcdd; color: black; }
The code of subgrid is the following
subGrid: true,
subGridRowExpanded: function (subgridId, rowid) {
var $subgrid = $("<table id='" + subgridId + "_t'></table>");
$subgrid.appendTo("#" + subgridId);
$subgrid.jqGrid({
datatype: "local",
data: $(this).jqGrid("getLocalRow", rowid).files,
colNames: ["Name", "Filetype", "col3", "col4"],
colModel: [
{name: "name", width: 130, key: true, frozen: true},
{name: "filetype", width: 130, frozen: true},
{name: "col3", width: 130},
{name: "col4", width: 130}
],
height: "100%",
rowNum: 10,
sortname: "name",
shrinkToFit: false,
autowidth: true,
idPrefix: "s_" + rowid + "_"
}).jqGrid("setFrozenColumns");
}
I use shrinkToFit: false to prevent default shrinking of columns of subgrids together with autowidth: true which set the width of the subgrid.
The code works in jqGrid 3.7 or free jqGrid 3.8 which I published recently (see here and here), but in case of usage more old versions of jqGrid you can need to trigger jqGridAfterGridComplete event (see the answer).

How to add navgrid options to a modal form?

I have to display an add modal form when the page loads. I do so thusly:
$('#lst_totals').jqGrid('editGridRow','new');
Problem is, I don't know how to set the navgrid when I call it in this way. I set the options on the add modal form in the navgrid like this:
// add options
{ bSubmit: "Add",
width: 350,
recreateForm: true,
recreateFilter: true,
closeOnEscape: true,
closeAfterAdd: true,
editData: { action:'grdTotals' },
},
But these properties are not set for the add modal form I called when the page loads. They only apply to add modal forms that are shown when the add button is clicked. How do I apply options to modal forms that are called from outside of the jqGrid?
Here's the solution. It's as simple as I knew it would be:
$('#lst_totals').jqGrid('editGridRow','new',
{ bSubmit: "Add",
width: 350,
recreateForm: true,
recreateFilter: true,
closeOnEscape: true,
closeAfterAdd: true,
editData: { action:'grdTotals' },
}
);
Basically, since I'm creating a new modal form that's not really part of the navgrid, I have to give it the properties I want it to have. Above, the 'editGridRow' accepts a third parameter {} which can contain these properties.

How to remove cancel button from jqgrid add form?

jqgrid add dialog have two buttons(submit and cancel). A message will be displayed when i click the cancel button. That message box have 3 buttons(yes, no and cancel). Now i want to remove the cancel button. any possibilities........?
Sorry for my bad english.
Thank you.
sample coding for jqgrid
<sjg:grid id="gridtable"
caption="Customer List"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="customerList"
rowNum="10"
autowidth="true"
editurl="%{editurl}"
editinline="false"
navigator="true"
navigatorAdd="true"
navigatorAddOptions="{
viewPagerButtons: false,
recreateForm: true,
checkOnUpdate: true,
closeAfterAdd: true,
height: 275,
width: 600,
draggable: false,
resizable: false
}"
navigatorDelete="true"
navigatorEdit="true"
navigatorRefresh="true"
navigatorSearch="true"
navigatorEditOptions="{
viewPagerButtons: false,
recreateForm: true,
checkOnUpdate: true,
closeAfterEdit: true,
height: 275,
width: 600,
draggable: false,
resizeable: false
}"
navigatorDeleteOptions="{ checkOnUpdate: true}"
navigatorViewOptions="{
viewPagerButtons: false,
recreateForm: true,
checkOnUpdate: true,
height: 225,
width: 620,
draggable: false,
resizeable: false
}"
navigatorSearchOptions="{
sopt:['eq','ne','lt','gt','in','ni','cn','nc'],
closeAfterSearch: true
}"
navigatorView="true"
rownumbers="true"
rowList="10,20,30"
viewrecords="true"
>
Thank you so much.
Here i am specifing that cancel button
how to remove this cancel button?
I need only yes and no buttons.
Using grid API how it can be possible i dont know but,using jquery you can hide this button in following way :
$("#gridtable #cNew).css({'display':'none'});
'#cNew' is id of that button or you can get id of Cancle button by right click on that button and select inspect element in mozila webbrowser or use firebug to get id of that button and then replace that id with #cNew.
I think you can apply it to each form add, edit, etc.
hide button cancel
onInitializeForm: function($form) {
$form.parent().find('#cData').hide();
}
or if you want hide button submit
beforeShowForm: function ($form) {
$form.parent().find('#sData').hide();
},

jqGrid and Firefox autocomplete conflict

I have a jqGrid constructed as it follows in the code below:
function radio(value, options, rowObject){
var radio = '<input type="radio" value=' + value + ' name="radioid" />';
return radio;
}
function reloadOnEnter(){
jQuery(':input[name=field1]').keyup(function(e){
if(e.keyCode == 13){
var fieldValue = jQuery(':input[name=field1]').attr('value');
jQuery(':input[name=field1]').attr('value', fieldValue);
jQuery("#listTable").jqGrid().trigger("reloadGrid");
}
});
}
jQuery(function(){
jQuery("#listTable").jqGrid({
url: '$content.getURI("myURI")' + '?userId=$userId&pageNo=0&locale=' + '$locale',
datatype: 'json',
mtype: 'POST',
colNames:['column1', 'column2', 'column3', 'column4', 'column5'],
colModel :[
{name:'name', index:'field', width:'8%', search:false, align:'center', formatter: radio, editable:false, sortable: false, resizable:false},
{name:'name1', index:'field1', width:'23%', sortable: false, resizable:false},
{name:'name2', index:'field2', width:'23%', sortable: false, resizable:false},
{name:'name3', index:'field3', width:'23%', sortable: false, resizable:false},
{name:'name4', index:'field4', width:'23%', sortable: false, resizable:false}
],
width:'768',
height: 500,
pager: '#pagerDiv',
gridview: true,
rowNum: $rowNr,
rowTotal: 500,
sortorder: 'desc',
viewrecords: true,
loadComplete: loadCompleteHandler,
ignoreCase: true
});
});
jQuery(function(){
jQuery("#listTable").jqGrid('filterToolbar',{
stringResult: true,
searchOnEnter: false });
});
I start typing 'he' and the autocomplete window shows me 'hello' (because I previously typed hello). I select 'hello' and hit enter, and still 'he' is submitted in the ajax request.
My reloadOnEnter function is called by the loadCompleteHandler. The interesting thing is that when I query the search field (field1) value is the selected value, but only the typed value is being sent in the request. I would like to send the selected value. How can i achieve this?
EDIT:
The loadCompleteHandler looks like this:
function loadCompleteHandler(){
reloadOnEnter();
jQuery("#listTable").jqGrid('setGridHeight', Math.min(500,parseInt(jQuery(".ui-jqgrid-btable").css('height'))));
}
(I use Apache Velocity as a template engine! That is why I have variables like $variable in the javascript code!)
To your main question: you should use jQuery.val function instead of jQuery.attr('value').
Many other things in your code seams me strange or unclear. It is not clear for me how you use reloadOnEnter in the loadCompleteHandler. If would be good if you include the corresponding code fragment. The value for the url seems me also very strange. You use additionally searchOnEnter: false option of filterToolbar but in the reloadOnEnter you wait for the 'Enter' key. Inside of the body of if(e.keyCode == 13) you get jQuery(':input[name=field1]').attr('value') and then set the same value back. Why?
Probably you could describe in the text of your question a little more what you want to archive with the code?

Fill jqgrid with data from visualforce page

I have a visualforce page and I am using jqgrid to display data on this page. The url that the jqgrid points to is a visualforce page(https://test.visual.force.com/apex/GridResults) which outputs only JSON data. This page does not have any header or html information.
The problem is that when I run this page, the grid renders with column names but no data.
When I run the url it outputs JSON data. I have pasted below the code.
jQuery("#list").jqGrid({
url:"https://test.visual.force.com/apex/GridResults",
datatype: "json",
colNames: [{!fieldNames}], -- property in controller which outputs fieldnames
colModel: [{!colModel}], -- property in controller which outputs column definition
rowNum: 10,
rowTotal:10,
rowList: [20, 40, 60],
loadonce:true,
mtype:"GET",
gridView:true,
pager: '#pager',
sortname: 'Record ID',
sortorder: "desc",
width: 1200,
height: 400,
caption: "Accounts"
});
jQuery("#list").jqGrid('navGrid', "#pager", { edit: true, add: true, del: false })
};
Any ideas on why the data from the page is not consumed by the jqgrid? Help much appreciated.
Have you look into Visualforce remoting?

Resources