I am new to JQGrid, i am developing a screen where i need to use a tool bar in JQ Grid and perform search operation accordingly.
I have a date field in my JqGrid and i have added the DtPicker in the Search option also.
But when i select the date from DTPicker, search for the selected date is not performed.
Please let me know how to perform search for selected date.
<table id="test">
</table>
<div id="divtest">
</div>
<div>
<asp:Label ID="count" runat="server" Text="Label"></asp:Label>
</div>
<script type="text/javascript">
$(document).ready
(
function CreateGrid()
{
var lastSel,lastSel1, Status = ["All", "Active", "InActive"],defaultStatus="Active";
jQuery("#test").jqGrid
(
{
url:'Test.aspx',
datatype:'json',
contentType: "application/json; charset=utf-8",
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
colNames:[ 'EMPID',
'EMPName',
'DOB',
'Designation',
'Genders',
'Status',
'Remarks',
'EMPType',
''
],
colModel:
[
{
name:'EMPID',
index:'EMPID',
width:120,
sorttype:'int',
editable:false,
key:true,
sortable: true,
search:true,
editoptions:{readonly:true}
},
{
name:'EMPName',
index:'EMPName',
width:250,
sortable: true,
align:"left",
editable:true,
size:100,
editrule:{custom:true,custom_func:checkName}
},
{
name:'DOB',
index:'DOB',
width:250,
sortable: true,
align:"left",
size:100,
editable:true,
sorttype:"date",
formatter: "date",
formatoptions: {newformat:'m/d/Y'},
editrule:{custom:true,custom_func:checkName}
,editoptions:
{"dataInit":function(el)
{setTimeout(function(){if(jQuery.ui){
if(jQuery.ui.datepicker)
{
jQuery(el).datepicker({"disabled":false,
"dateFormat":"mm/dd/yy"
,changeMonth: true,
changeYear: true,
recreateForm: true});
jQuery('.ui-datepicker').css({'font-size':'69%'});
}
}},100);}
}
,searchoptions:
{"dataInit":function(el)
{setTimeout(function(){if(jQuery.ui) {
if(jQuery.ui.datepicker)
{
jQuery(el).datepicker({"disabled":false,
"dateFormat":"mm/dd/yy"
,changeMonth: true,
changeYear: true,
recreateForm: true});
jQuery('.ui-datepicker').css({'font-size':'69%'});
}
}},100);}
},
search:true
},
{
name:'Designation',
index:'Designation',
width:250,
align:"left",
editable:true,
size:100,
sortable: true,
formatter:'select',
edittype: 'select',
editoptions: {value:"0:select;1:CEO;2:HR;3:Manager;4:Team Lead;5:Software Engineer; 6:Tester;7:Sales;8:Others"}
,editrule:{custom:true,custom_func:checkDropDown}
,stype:'select',
searchoptions: {
sopt:['eq'],value:":All;1:CEO;2:HR;3:Manager;4:Team Lead;5:Software Engineer;6:Tester;7:Sales;8:Others"
}
},
{
name:'Gender',
index:'Gender',
width:150,
align: 'left',
editable:true,
size:100,
sortable: true,
formatter:'select',
edittype: 'select',
editoptions: {value: "0:select;1:Male;2:Female"},
editrule:{custom:true,custom_func:checkDropDown},
stype:'select',
searchoptions: {
sopt:['eq'],value:":All;1:Male;2:Female"
}
},
{
name:'Status',
index:'Status',
width:150,
align: 'left',
editable:true,
size:100,
sortable: true,
formatter:'select',
edittype: 'select',
editoptions: {value: "0:select;1:Active;2:InActive"}
,editrule:{custom:true,custom_func:checkDropDown},
stype:'select'
,searchoptions: {
sopt:['eq'],value:":All;1:Active;2:InActive"
}
},
{
name:'Remarks',
index:'Remarks',
width:150,
sortable: true,
align:"left",
editable:true,
edittype:"textarea",
editoptions:{rows:'3',cols:'10'},
size:100
},
{
name:'Emptype',
index:'Emptype',
sortable: true,
formatter:'checkbox',
editable:true,
edittype:"checkbox",
stype:'select',
searchoptions: {
sopt:['eq','ne'],value:":All;true:In;false:Out"
}
},
{
name:'action',
index: 'action',
sortable:false,
align:'center',
formatter:"actions",
formatoptions:{key:true},
search:false
}
],
rowNum:10,
rowList:[2,5,10,15],
pager:'#divtest',
viewrecords:true,
width:0.96*screen.width,height:0.42*screen.height,
caption:'jqGrid',
emptyrecords: "No Results Found",
sortable:true,
sortorder: "desc",
search:true,
ignoreCase:true,
loadonce:true,
multiselect: true,
shrinkToFit:true,forceFit:true
,editurl:"Test4.aspx",
onAfterSaveCell:
function reload(result)
{
$("#grid").trigger("reloadGrid");
}
,onSelectRow:
function (id)
{ var tr;
if (id && id !== lastSel)
{
if (typeof lastSel !== "undefined")
{
$("#test").jqGrid('restoreRow', lastSel);
$("#test").trigger("reloadGrid",[{current:true}]);
}
lastSel = id;
}
}
}
).jqGrid('navGrid','#divtest',
{ edit:false,
add:true,
del:false,
search:false
},
//for Edit
{
},
//for Add
{
top:0.20*screen.height,
left:(screen.width-(0.65*screen.width)),
width: 0.35*screen.width,
align:'Center',
resizeable: true,
closeAfterAdd:true,
reloadAfterSubmit:true,
serializeEditData: function(data)
{
return (data);
},
beforeShowForm: function(form)
{
$("#DOB").datepicker
({
changeMonth: true,
recreateForm: true,
changeYear: true
});
}
},
//for Delete
{
},
//for Search
{ multipleSearch: true,
multipleGroup:true,
//showQuery: true,
closeOnEscape: true,
closeAfterSearch: true,
overlay: 0,
beforeShowSearch:function()
{
$("#test")[0].toggleToolbar();
},
onClose: function()
{
$("#test")[0].toggleToolbar();
}
}
).jqGrid('navButtonAdd','#divtest',
{
caption:" ",
width:'15',
buttonicon:"ui-icon-search",
onClickButton: function()
{
$("#test")[0].toggleToolbar();
},
position:"last"
})
//For displaying the blank tool bar on the grid
.jqGrid('filterToolbar',
{
stringResult: true,
searchOnEnter: false,
defaultSearch: "cn"
}
)
.jqGrid('inlineNav',"#pager",{
edit:false,
editicon: "ui-icon-pencil",
add:true,
addicon:"ui-icon-plus",
cancel: true,
cancelicon:"ui-icon-cancel",
save: true,
saveicon:"ui-icon-disk"
}
);
//The Date DTPicker field in the Edit portion.
var initDateEdit =
function(elem)
{
setTimeout(function()
{
$(elem).datepicker(
{
dateFormat: 'mm/dd/yy',
autoSize: true,
//showOn: 'button',
changeYear: true,
changeMonth: true,
showButtonPanel: true,
recreateForm: true,
showWeek: true
});
},100);
}
,
//The Date DTPicker field in the Search portion.
//But not working in this.
initDateSearch =
function(elem)
{
setTimeout(function()
{
$(elem).datepicker(
{
dateFormat: 'mm/dd/yy',
autoSize: true,
//showOn: 'button',
changeYear: true,
changeMonth: true,
showButtonPanel: true,
recreateForm: true,
showWeek: true
});
},100);
}
;
//To hide the check box or select box in the Header of the JQGrid.
var myGrid = $("#test");
$("#cb_"+myGrid[0].id).hide();
var grid = $("#test"),
getColumnIndexByName = function (grid, columnName)
{
var cm = grid.jqGrid('getGridParam', 'colModel'), i, l = cm.length;
for (i = 0; i < l; i++)
{
if (cm[i].name === columnName)
{return i;}
}
return -1;
};
}
);
</script>
Thanks and Regards,
NMB
You just need to add this after your Filter tool bar..
.change(function(){$("#table_ID")[0].toggleToolbar()})
Related
in my asp.net mvc, using jqGrid to bind the data. code is as below. But its not loading the data and not hitting the controller action when debugging. what's the problem in this below code. Alert is showing the url but not hitting the controller action. Help would be appreciate. Please let me know if you need more information
#model Stud.Areas.Admin.Models.AdminVM
#using Stud.Common.Extension;
<h2>MD Index</h2>
<br />
<div style="margin-top: -45px">
<div class="col-md-12">
<div id="gridDivmsg" style="clear: both;">
<table id="jqGrid" ></table>
<div id="jqGridPagermsg"></div>
</div>
</div>
</div>
#section scripts{
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>
#*<script src="~/Scripts/MDScript.js"></script>*#
#Html.jqGridSetup()
<script>
$(document).ready(function () {
var $grid = $('#jqGrid');
var $gridDiv = $('#gridDivmsg');
function reloadGridmsg() {
var urlName = '#Url.Action("GetMessagesForGrid", "MD")';
$grid.jqGrid("setGridParam", { url: urlName, datatype: "json", page: 1 }).trigger("reloadGridmsg");
$gridDiv.show();
alert(urlName);
}
$grid.jqGrid({
editurl: '#Url.Action("EditRowMessage")',
datatype: 'local',
styleUI: 'Bootstrap',
colNames: ['Id', 'Message Key', 'Message Value', 'Message Status'],
colModel: [
{ name: 'Id', index: 'Id', width: 1, hidden: true, editable: true, edittype: 'text', editrules: { required: true } },
{ name: 'MessageKey', index: 'MessageKey', width: 1, editable: true, edittype: 'text', editrules: { required: true } },
{ name: 'MessageValue', index: 'MessageValue', width: 1, editable: true, edittype: 'textarea', editrules: { required: true } },
{ name: 'MessageStatus', index: 'MessageStatus', width: 1, editable: true, edittype: 'select', editoptions: { value: { 'Active': 'Active', 'InActive': 'InActive' }, defaultValue: 'Active' }, editrules: { required: true } }
],
responsive: true,
loadonce: true,
pager: $('#jqGridPagermsg'),
height: 'auto',
sortname: 'Id',
rowNum: 20,
autowidth: true,
viewrecords: true,
altRows: true,
altclass: 'jqGridAltRow'
});
$grid.jqGrid('filterToolbar', { autosearch: true, searchOnEnter: false, defaultSearch: "cn" });
$grid.jqGrid('navGrid', "#jqGridPagermsg", {
edit: true,
add: true,
del: false,
search: false,
refresh: false,
view: false,
position: "left",
cloneToTop: false
},
{
editCaption: "Edit User",
recreateForm: true,
checkOnUpdate: true,
checkOnSubmit: true,
closeAfterEdit: true,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
},
afterComplete: function () {
reloadGridmsg();
}
},
{
addCaption: "Add User",
closeAfterAdd: true,
recreateForm: true,
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
},
afterComplete: function () {
reloadGridmsg();
}
},
{
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
});
reloadGridmsg();
});
</script>
}
Controller Action method is as below.
public ActionResult GetMessagesForGrid(StudVM model)
{
if (!IsAuthorized(Enums.Rights.Admin))
return View("NoAccess");
var gridData = _activityService.GetVCRMessagesList();
int totalRecords = gridData.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)model.rows);
var jsonData = new
{
total = totalPages,
page = model.page,
records = totalRecords,
rows = gridData.Select(d => new { Id = d.Id, cell = new object[] { d.Id, d.MessageKey, d.MessageValue, d.MessageStatus } }).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
till i'm getting blank grid as below
enter image description here
Your controller is having a parameter model of type StudVM which is not passed in your javascript url.
Try passing parameter of type StudVM. It may resolve your issue.
$grid.jqGrid("setGridParam", { url: urlName,postData: { model:<your model>}, datatype: "json", page: 1 }).trigger("reloadGridmsg");
You need to have the action method follow some method signature as follows
public ActionResult GetMessagesForGrid(string sidx, string sord, int page, int rows, bool _search, string filters)
{
if (!IsAuthorized(Enums.Rights.Admin))
return View("NoAccess");
var gridData = _activityService.GetVCRMessagesList();
int totalRecords = gridData.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / rows);
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = gridData.Select(d => new { Id = d.Id, cell = new object[] { d.Id, d.MessageKey, d.MessageValue, d.MessageStatus } }).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
I also don't see a reason why you don't make the grid datatype to json and specify the url in the begging when you define the grid instead of making the grid client side and then reloading it
$grid.jqGrid({
editurl: '#Url.Action("EditRowMessage")',
datatype: 'json',
url: '#Url.Action("GetMessagesForGrid", "MD")'
styleUI: 'Bootstrap',
colNames: ['Id', 'Message Key', 'Message Value', 'Message Status'],
colModel: [
{ name: 'Id', index: 'Id', width: 1, hidden: true, editable: true, edittype: 'text', editrules: { required: true } },
{ name: 'MessageKey', index: 'MessageKey', width: 1, editable: true, edittype: 'text', editrules: { required: true } },
{ name: 'MessageValue', index: 'MessageValue', width: 1, editable: true, edittype: 'textarea', editrules: { required: true } },
{ name: 'MessageStatus', index: 'MessageStatus', width: 1, editable: true, edittype: 'select', editoptions: { value: { 'Active': 'Active', 'InActive': 'InActive' }, defaultValue: 'Active' }, editrules: { required: true } }
],
responsive: true,
// loadonce: true,
pager: $('#jqGridPagermsg'),
height: 'auto',
sortname: 'Id',
rowNum: 20,
autowidth: true,
viewrecords: true,
altRows: true,
altclass: 'jqGridAltRow'
});
if you need to know how to make that action method custom look at
This solution
Could you please help me how I could do to delete multiple records selected in my jqgrid? I've tried a number of ways, but so far not got any success. I will be grateful to anyone who can help me.
jQuery("#grid-table").jqGrid({
//direction: "rtl",
url: "/Lojas/GetLojas",
datatype: 'json',
mtype: 'Get',
height: '100%',
colNames: [ ' ',
'Name',
'Description'
],
colModel: [
{
name: 'myac', index: '', width: 65, fixed: true, sortable: false, resize: false,
formatter: 'actions',
formatoptions: {
keys: true,
delOptions: { recreateForm: true, url: '/Lojas/Delete', beforeShowForm: beforeDeleteCallback },
editformbutton: true, editOptions: { recreateForm: true, url: '/Lojas/Edit', closeAfterEdit: true, beforeShowForm: beforeEditCallback, closeOnEscape: true }
}
},
{ key: true, hidden: true, name: 'Id', index: 'Id', sorttype: "int", editable: false },
{ key: false, name: 'Name', index: 'Name', editable: true},
{ key: false, name: 'Description', index: 'Description', editable: true}
],
viewrecords: true,
loadonce: true,
rowNum: 10,
rowList: [5, 10, 15],
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
Id: "0"
},
pager: pager_selector,
altRows: true,
autowidth: true,
multiselect: true,
multiboxonly: true,
sortorder: "desc",
multiboxonly: true,
caption: "Lojas Cadastradas"
});
//navButtons
jQuery("#grid-table").jqGrid('navGrid', pager_selector,
{
edit: true,
add: true,
del: true,
search: true,
refresh: true,
view: true,
},
{
url: '/Lojas/Edit',
closeOnEscape: true,
closeAfterEdit: true,
recreateForm: true
},
{
url: '/Lojas/Create',
closeOnEscape: true,
closeAfterAdd: true,
recreateForm: true
},
{
url: '/Lojas/Delete',
closeOnEscape: true,
closeAfterDelete: true,
recreateForm: true
},
{
//search form
recreateForm: true,
closeOnEscape: true,
closeAfterSearch: true,
multipleSearch: true
},
{
//view record form
recreateForm: true
}
)
Code in my controller:
public ActionResult Delete(Loja loja)
{
Loja lojaToDelete = db.Lojas.Find(loja.Id);
if (lojaToDelete == null)
{
return HttpNotFound();
}
db.Lojas.Remove(lojaToDelete);
db.SaveChanges();
return View(loja);
}
I recommend you to change prototype of Delete function public ActionResult Delete(Loja loja) to
public void Delete(string id)
The main problem in your code is the following. Corresponds to the documentation jqGrid post id parameter to url: '/Lojas/Delete'. You can rename the name of id parameter using prmNames. In the case you can use prmNames: {id: "Id"}, but it's not really required.
If multiple rows needed be deleted then id string will be comma separated and you can use something like
public void Delete(string id)
{
var ids = id.Split(',');
foreach (lojaId in ids) {
Loja lojaToDelete = db.Lojas.Find(lojaId);
if (lojaToDelete == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
db.Lojas.Remove(lojaToDelete);
}
db.SaveChanges();
}
Only WWID column is disabled not both columns are disabledenter code here please help me to disable two or more columns
colNames: ['UserName','WWID', 'Generic', 'Mac'],
colModel: [
{ name: 'UserName', index: 'UserName', key: true, width: '200', editable: true, sortable: true, align: 'center' },
{ name: 'WWID', index: 'WWID', width: '250' , editable: true, sortable: true,sorttype:'int', align: 'center' },
{ name: 'Generic', index: 'generic', width:'200', editable: true, sortable: true,sorttype:'text', align: 'center' },
{ name: 'Mac', index: 'mac', width:'200', editable: true, sortable: true,sorttype:'int', align: 'center' },
],
...............
});
jQuery("#gridId").jqGrid('navGrid', '#gridpager',
{ edit: true, add: true, del: true, search: true, excel: true, exceltext: 'Excel', cloneToTop: true },
{ // edit option
url: "Uploading.ashx", closeAfterEdit: true,afterSubmitCell: function () { $('#gridId').trigger('reloadGrid');},
beforeShowForm: function (form) { $('#tr_UserName', form).hide(); },
beforeShowForm: function(form) { $('#tr_WWID', form).hide(); }
},
{ // add option
url: "Uploading.ashx", closeAfterAdd: true,
beforeShowForm: function(form) { $('#tr_UserName', form).show(); },
beforeShowForm: function (form) { $('#tr_WWID', form).show(); }
},
You should provide only one beforeShowForm callback which will show/hide both rows. In your case only the last one provided is being used. Your code should be like this:
jQuery("#gridId").jqGrid('navGrid', '#gridpager',
{ edit: true, add: true, del: true, search: true, excel: true, exceltext: 'Excel', cloneToTop: true },
//Edit options
{
url: "Uploading.ashx",
closeAfterEdit: true,
afterSubmitCell: function () { $('#gridId').trigger('reloadGrid'); },
beforeShowForm: function (form) { $('#tr_UserName', form).hide(); $('#tr_WWID', form).hide(); }
},
//Add options
{
url: "Uploading.ashx",
closeAfterAdd: true,
beforeShowForm: function(form) { $('#tr_UserName', form).show(); $('#tr_WWID', form).show(); }
},
...
);
jQuery("#gridId").jqGrid('navGrid', '#gridpager',
{ edit: true, add: true, del: true, search: true, excel: true, exceltext: 'Excel', cloneToTop: true },
//Edit options
{
url: "Uploading.ashx",
closeAfterEdit: true,
afterSubmitCell: function () { $('#gridId').trigger('reloadGrid'); },
beforeShowForm: function (form) { $('#tr_UserName', form).hide(); $('#tr_WWID', form).hide(); }
},
//Add options
{
url: "Uploading.ashx",
closeAfterAdd: true,
beforeShowForm: function(form) { $('#tr_UserName', form).show(); $('#tr_WWID', form).show(); }
},
...
);
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
$(document).ready(function () {
jQuery("#tOceanC_ds_list").jqGrid({
// add by default to avoid webmethod parameter conflicts
// add by default to avoid webmethod parameter conflicts
url: "Default.aspx?cmd=select",
datatype: "json",
colNames: ['BOQID', 'BOQType', 'Description', 'Quantity'],
colModel:[
{ name: "BOQID", hidden: true, index: "BOQID", jsonmap: "BOQID",search:true,key:true,editable:true },
{ name: "BOQType", summaryTpl: "{0}", editable: true, searchoptions: {}, index: "BOQType", width: 200, align: "center", jsonmap: "BOQType", searchoptions: {}},
//{ name: "Description", editable: true, index: "Description", width: 200, align: "center", jsonmap: "Description", search: true },
{ "editoptions": { dataInit: function (el) { setTimeout(function () { var ec = 'DatePicker1'; if (typeof (jQuery(el).datepicker) !== 'function') alert('JQDatePicker javascript not present on the page. Please, include jquery.jqDatePicker.min.js'); jQuery(el).datepicker(eval(ec + '_dpid')); }, 200); } }, "summaryTpl": "{0}", "editable": true, "edittype": "text", "searchoptions": { dataInit: function (el) { setTimeout(function () { var ec = 'DatePicker1'; if (typeof (jQuery(el).datepicker) !== 'function') alert('JQDatePicker javascript not present on the page. Please, include jquery.jqDatePicker.min.js'); jQuery(el).datepicker(eval(ec + '_dpid')); }, 200); } }, name: "Description", index: "Description" },
{ name: "Quantity", editable: true, index: "Quantity", width: 200, align: "center", jsonmap: "Quantity", search: true }
],
viewrecords: true, scrollrows: false, postBackUrl: "__doPostBack('#tOceanC_ds_list','jqGridParams')",
editDialogOptions: { editCaption: "Edit Dialog", resize: false, closeAfterEdit: true, processData: "Default.aspx", bSubmit: "Submit", bCancel: "Cancel Editing", modal: true, recreateForm: true, errorTextFormat: function (data) { return 'Error: ' + data.responseText } },
addDialogOptions: { recreateForm: true, errorTextFormat: function (data) { return 'Error: ' + data.responseText } },
delDialogOptions: { errorTextFormat: function (data) { return 'Error: ' + data.responseText } },
searchDialogOptions: {left:300,top:400,resize:false},viewRowDetailsDialogOptions: {},jsonReader: { id: "BOQID" },
rowNum: 10,
height: "60%",
rownumbers: true,
autowidth: true,
shrinkToFit: false,
rowList:[10,20,30,50,100],
pager: jQuery("#OceanC_pager"),
viewrecords: true,
multiselect: false,
sortorder: "desc",
caption:"List of Users",
editurl: "Default.aspx",
//serializeGridData: function (data) {
// return $.toJSON(data);
//},
jsonReader: { repeatitems : false, id: "0" }
});
jQuery("#tOceanC_ds_list").jqGrid("navGrid", "#OceanC_pager", { add: false, edit: true, del: true, search: true, view: true,reload:true}, {}, {}, {}, { multipleSearch: false }, jQuery('#tOceanC_ds_list').getGridParam('editDialogOptions'), jQuery('#tOceanC_ds_list').getGridParam('addDialogOptions'), jQuery('#tOceanC_ds_list').getGridParam('delDialogOptions'), jQuery('#tOceanC_ds_list').getGridParam('searchDialogOptions'), jQuery('#tOceanC_ds_list').getGridParam('viewRowDetailsDialogOptions')).bindKeys()
});
function customPhoto(cellVal, options, rowObject){
return "<img src='assets/img/" + cellVal + "' height='50' width='50' >";
}
</script>
The editurl don't pass the parameter to edit the data like oper, del, edit, add
I want editurl to pass these parameter to code behind when I request.querystring["oper"] it return the empty or request.querystring["del"] it return empty
I am using asp.net webform 3.5 framework
hii Guys !!
I implemented filter with dropdownlist in jqgrid but grid is not showing the values of the column on which i added filter neither is filtering the data..
Here is my code...
<script type="text/javascript">
var categoriesStr = ":All;1:vikas;2:Ankur";
$(function () {
$("#UsersGrid").jqGrid({
url: 'getGriddahico.ashx',
datatype: 'json',
height: 250,
colNames: ['UserID', 'UserName', 'FirstName', 'MiddleName', 'LastName', 'EmailID'],
colModel: [
{ name: 'UserID', index: 'UserID', width: 100, sortable: true, align: 'center' },
{ name: 'UserName', width: 100, sortable: true, align: 'center' , formatter: 'select', stype: 'select',
sorttype: function (cell) { return categories[cell]; },
edittype: 'select', editoptions: { value: categoriesStr },
searchoptions: { sopt: ['eq'] }
},
{ name: 'FirstName', width: 100, sortable: true, align: 'center' },
{ name: 'MiddleName', width: 100, sortable: true },
{ name: 'LastName', width: 100, sortable: true, align: 'center' },
{ name: 'EmailID', width: 150, sortable: true, align: 'center' }
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#UsersGridPager',
sortname: 'UserID',
loadonce: true,
viewrecords: true,
ignorecase:true,
sortorder: 'asc',
autowidth: true,
toppager: true,
height: '100%'
});
$("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false, search: false });
$("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "cn", beforeSearch: function () {
//alert("verifying the data");
var postData = grid.jqGrid('getGridParam', 'postData');
// we use `stringResult: true` so decoding of the search parameters are a little complex
var searchData = jQuery.parseJSON(postData.filters);
for (var iRule = 0; iRule < searchData.rules.length; iRule++) {
if (searchData.rules[iRule].field === "UserName") {
var valueToSearch = searchData.rules[iRule].data;
if (valueToSearch.length != 5) {
alert("The search string MUST de 5 charachters length!");
return true; // error
}
}
}
return false;
}
});
//jQuery("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });
});
</script>
Anyhelp will be welcomed ...
Thanx in advance
May be getGriddahico.ashx is not returning sorted values.
if u could share the code of getGriddahico.ashx, it would be better.