i am working on jqgrid. i want to add refresh button to jqgrid toolbar to refresh the grid.
here is my js code:
jQuery(document).ready(function () {
var grid = jQuery("#gridemp");
grid.jqGrid({
url: '/Admin/GetTimeInOut_ForAdmin',
datatype: 'json',
mtype: 'Post',
height: '100%',
multipleSearch: false,
rownumbers: true,
//formatCell: emptyText,
colNames: ['User', 'Date', 'TimeIn', 'TimeOut'],
colModel: [
{ name: 'User', index: 'User', align: "center", sorttype: 'text', resizable: true, editable: false },
{ name: 'Date', index: 'Date', align: "center", sorttype: 'text', resizable: true, editable: false, searchoptions: { dataInit: function (el) { $(el).datepicker({ dateFormat: 'mm/dd/yy' }).change(function () { $('#gridemp')[0].triggerToolbar(); }); } } },
{ name: 'TimeIn', index: 'TimeIn', align: "center", sorttype: 'text', resizable: true, editable: false },
{ name: 'TimeOut', index: 'TimeOut', align: "center", sort:false, resizable: true, editable: false }
],
//shrinkToFit: true,
// loadonce: false,
//ignoreCase: true,
width: '690',
pager: '#emppager',
caption: 'Employee Time IN/OUT',
rowNum: 10,
rowList: [10, 20, 50, 100],
viewrecords: true,
hidegrid: false,
}
);
grid.jqGrid('filterToolbar',{ stringResult: true, searchOnEnter: true, defaultSearch: 'cn' });
grid.jqGrid('navGrid', '#emppager',
{ resize: false, add: false, search: false, del: false, refresh: false, edit: false, alerttext: 'Please select one user' }
).jqGrid('navButtonAdd', '#pager');
});
actually i need 2 refresh buttons one for to clear the search bar text boxes without refreshing the jqgrid, and one for refreshing the whole grid. i will mark your answer if it works for me. thanks in advance. happy coding :), if you the question is not clear please comment i will explain.
First of all it seems your code contains typing error: you use pager: '#emppager' during creating grid, in navGrid but not in navButtonAdd.
To add "standard" reload button which reset filter toolbar and reload the grid you need just remove refresh: false option.
To add custom clear filter you need call navButtonAdd in the way like below
.jqGrid("navButtonAdd", "#emppager", {
caption: "", // no text near the button
title: "Clear filters in toolbar without reloading of data",
buttonicon: "ui-icon-close", // an example of icon
onClickButton: function () {
this.clearToolbar(false); // don't reload grid
}
});
You can change icon used by Refresh button by usage refreshicon option (at the same place where you specify del, refresh, alerttext etc). Default value is refreshicon: "ui-icon-refresh". Moreover you can consider to use refreshstate: "current" (default is refreshstate: "firstpage").
Related
Using latest version of free jqgrid.
I am using the below code for my jqgrid.
I have some issues and question:
1) When I go to next page and previous page not sure what happens but my grid items keep moving up and down.
2) When I add/edit an item for form field I want the grid to refresh and get updated from the server but this does not happens and again my newly added data is lost in the grid as mentioned in my point1. I tried to add navOptions: { reloadGridOptions: { fromServer: true } } but still nothing.
3) When the user clicks on edit button on my pager it opens the user form field. I want the submit button to show edit instead of "Add" which it shows currently.
Here is my code below:
<script type="text/javascript">
$(function () {
"use strict";
var $grid = $("#list");
$grid.jqGrid({
url: '#Url.Action("GetData", "Home")',
datatype: "json",
mtype: 'Get',
colNames: ['Id', 'Name', 'Sex', 'Address'],
loadonce: true,
height: '100%',
autowidth: true,
emptyrecords: "No Users found.",
colModel: [
{ name: 'empid', index: 'empid', editable: true, editrules: { required: true}},
{ name: 'fname', index: 'fname', editable: true, editrules: { required: true}}, //currently these are texbox, but I want this to be label which gets filled based on the empid
{ name: 'lname', index: 'lname', editable: true, editrules: { required: true}},
{ name: 'address', index: 'address', editable: true, editrules: { required: true}}
],
cmTemplate: { autoResizable: true, editable: true },
autoResizing: { compact: true, resetWidthOrg: true },
iconSet: "fontAwesome",
guiStyle: "bootstrap",
rowNum: 10,
rowList: [5, 10, 20, "10000:All"],
viewrecords: true,
autoencode: true,
sortable: true,
pager: true,
rownumbers: true,
sortname: "empid",
sortorder: "desc",
pagerRightWidth: 150,
inlineEditing: {
keys: true
},
searching: {
loadFilterDefaults: false,
closeOnEscape: true,
searchOperators: true,
searchOnEnter: true,
caption: "Search",
Find: "Search"
},
editurl:'#Url.Action("GetDetails", "Home")',
formEditing: {
reloadGridOptions: { fromServer: true },
reloadAfterSubmit: true,
width: 460,
closeOnEscape: true,
closeAfterEdit: true,
closeAfterAdd: true,
closeAfterDelete: true,
savekey: [true, 13],
addCaption: "Add",
editCaption: "Edit",
bSubmit: "Add"
},
formDeleting: {
width: 320,
caption: 'Delete'
},
navOptions: { reloadGridOptions: { fromServer: true } }
}).jqGrid("navGrid")
.editGridRow("new", properties);
});
</script>
The first two items above I was able to resolve using below code:
navOptions: { reloadGridOptions: { fromServer: true } }
But the 3rd item I am still not able to resolve where I am not able to change the text of the Add button to change it to edit when the edit toolbar button is clicked
I am having a non-inline edit jqGrid containing an editable drop down column.
I use string as the editoptions.value, e.g. 1:A;A:B.
There is one option having the value same as the key of another option.
Then when I want to edit the record, the selected option is mapped wrongly. I found that this is due to the implementation in createEl function. It check $.trim(sv[1]) === $.trim(vl) to set the selected option also. May I know if there is anyone having the same problem?
I am using jqGrid 4.6.0. My code is as follows. Thanks a lot in advance.
var mydata = [
{ id: '1', col: '1' },
{ id: '2', col: 'A' }
];
var grid = jQuery("#grid");
grid.jqGrid({
data: mydata,
datatype: 'local',
colModel: [
{
name: 'col', width: 100, editable: true, formatter: 'select',
edittype: 'select', editoptions: { value: 'A:B;1:A' }
}
],
editurl: 'clientArray',
height: '100%',
viewrecords: true,
rownumbers: true,
pager: '#pager'
}).navGrid('#pager', { edit: true, add: true, del: false, search: false, refresh: false });
When do inline edit in jqgrid row, then it allows to do but, again click on another row then, it is not cancelling earlier row and both will remain in edit mode.
I need it to be cancel last one if user has clicked new row to edit as at single time, single row should be open for edit.
(if user click on next row to edit then, last row should be cancel out and new row only should open for edit).
Problem is here, it switch to the new row to edit but, "edit" and "cancel" button of last row remain as it is. Hence, simultaneously user can see two two row's edit, cancel buttons.
$("#SamplesGrdList").jqGrid({
url: '#Url.Action("ActionName", "Controller")/',
datatype: "json",
colNames: ['Category Name','ValueToChange','Edit'],
colModel: [
{ name: 'CategoryName', index: 'CategoryName', sortable: true, sorttype: 'text', width: 140, classes: 'bStyle' },
{
name: 'ValueToChange', index: 'ValueToChange', width: 82, align: "right", editable: true, editrules: { number: true, required: true, custom: true, custom_func: Deductions }, formatter: 'currency',
formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2, defaultValue: '0.00', prefix: '$ ' },
editoptions: {
style: 'width:70px;', dataEvents: [
{
type: 'blur',
fn: function (e) {
CalculateDeductions($(this).val());// SOme DB Operation
}
}
]
}
},
{
name: 'act', index: 'act', width: 60, align: 'center', sortable: false, formatter: 'actions',
formatoptions: {
keys: false,
delbutton: false,
onEdit: function (rowid) {
},
onSuccess: function (jqXHR) {
$("#SamplesGrdList").trigger('reloadGrid');
return true;
},
onError: function (rowid, jqXHR, textStatus) {
},
afterSave: function (rowid) {
},
afterRestore: function (rowid) {
$("#SamplesGrdList").trigger('reloadGrid');
}
}
}
],
rowNum: 10, rowList: [10, 20, 30],
sortname: 'CategoryName',
shrinkToFit: true,
sortable: true,
viewrecords: true,
sortorder: "desc",
footerrow: true,
width: '780',
height: '100%',
jsonReader:
{
root: 'List',
page: 'Page',
total: 'TotalPages',
records: 'TotalCount',
repeatitems: false,
id: 'Id'
},
editurl: '#Url.Action("ActionName", "ControllerName")'
});
Please guide how to resolve this so, at a time, single row is avaialble for edit/save/cancel.
NOTE: jqgrid version is Jquery.jqgrid-4.1.2.min.js
Thanks
I think that the only problem which you have: the usage of very old version jqGrid 4.1.2. I recommend you update to jqGrid 4.7 or free jqGrid 4.8.
Just try the demo for example. It uses formatter: "actions" which you need. You can verify that it works like you need.
I have an "actions" column in my grid and it's set to display the edit dialog when the edit icon is clicked. The form comes up fine, however, there doesn't seem to be a way to pass in options for the dialog box itself. When it comes up, it always has the scroll bars, default button text, etc. I have my ondblClickRow event also pulling up the edit dialog, but it allows me to set the height, width, modal, etc properties of the box. Ideally, I could wire up the ondblClickRow and the edit button click to a function, but that doesn't seem to be an option either.
colModel: [ { name: 'fx',
index: 'fx',
width: 60,
formatter: 'actions',
formatoptions: { editformbutton: true },
sortable: false,
sorttype: 'int',
summaryType: 'count', summaryTpl: '({0}) total' },
ondblClickRow: function(){
var gr = $("#mygrid").jqGrid('getGridParam', 'selrow');
$("#mygrid").jqGrid('editGridRow',
gr,
{height: 200,
width: 500,
modal: true,
resize: false,
reloadAfterSubmit: false,
bSubmit: 'Save',
recreateForm: false
});
}
Any ideas?
You can use formatoptions to specify any options of the editing. If you use formatter: 'actions' with formatoptions: { editformbutton: true } then form editing will be used. All other properties of form editing you can specify by delOptions and editOptions properties of formatoptions. If you starts editGridRow directly with some options I would recommend you to share the same options. The most easy way will be to save the options in a variable and to use it in both cases:
var myEditOptions = {
height: 200,
width: 500,
modal: true,
resize: false,
reloadAfterSubmit: false,
bSubmit: 'Save',
recreateForm: true,
closeAfterAdd: true,
closeAfterEdit: true
},
myDeleteOptions = {
// just an example of delGridRow options
reloadAfterSubmit: false,
closeOnEscape: true
};
$("#gridId").jqGrid({
colModel: [
{ name: 'fx', width: 60, formatter: 'actions', sortable: false,
formatoptions: {
editformbutton: true,
editOptions: myEditOptions,
delOptions: myDeleteOptions
}
},
...
],
...
ondblClickRow: function (rowid) {
$(this).jqGrid('editGridRow', rowid, myEditOptions);
}
});
In my jqGrid I want to pass in 5 rows from my model and display 3 of them in the grid but have all 5 show up in the edit and add popup window that jqGrid generates. I know I can add the hidden: true attribute in the colModel settings to prevent it from showing up but this also hides it from the popup window. Is there some way of hiding columns from the grid but show it when adding or editing data?
My Grid code:
<script type="text/javascript">
$( document ).ready( function ()
{
$( '#Sections' ).jqGrid( {
url: '#Url.Action("GetData")',
datatype: 'json',
mtype: 'GET',
colNames: ['ID', 'RouteName', 'Title', 'File', 'Description'],
colModel: [
{ name: 'ID', index: 'ID', width: 10, sorttype: 'int' },
{ name: 'RouteName', index: 'RouteName', width: 50, editable: true, edittype: 'text'},
{ name: 'Title', index: 'Title' },
{ name: 'File', index: 'File', hidden: true },
{ name: 'Description', index: 'Description', hidden: true }
],
autowidth: true,
height: '100%',
pager: $( '#SectionsPager' ),
sortname: 'ID',
viewrecords: true,
loadonce: true,
ignoreCase: true,
multiSort: true,
} );
$( '#Sections' ).jqGrid( 'navGrid', '#SectionsPager',
//enabling buttons
{ add: true, del: false, edit: true, search: true },
//add options
{ width: 'auto' },
//edit options
{ width: 'auto' },
//delete options
{}
);
} );
</script>
Via Oleg's answer at
Sending additional parameters to editurl on JQgrid
hidden: true, editable: true, editrules: { edithidden: true}, hidedlg: true
The editrules: { edithidden: true} section will "turn on" your column when editing.
u can use beforeShowForm in your add/edit and make it hidden or not
beforeShowForm: function(form) {
$("#tr_columnname").hide();
$("#tr_columnname").show();
}