How can i have greater than or lesser than in the Searchbox?
below is my search code:
{multipleSearch:true}
Searchbox is showing only this
Is there a settings that i need to set for jgGrid to recognize the field date as Date? it appears that it was being read as text.
below is my colModel for date
{name:'date', index:'date', width:90, editable:false, align:"center", editrules:{required:true}}
The behavior which you described exists since introduction of the new filter module in jqGrid. The default behavior is just a little too complex to be described in the "Default" column of the table from the options of searching.
If you examine the source code of jqGrid you will find the following two lines:
numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
So if you have defined sopt property in the searchoptions for some column of jqGrid you will see the corresponding compare operations. You can set default
If you would define any sorttype value other as default 'string' the numerical options will be used as the compare operations. Only for undefined sorttype, undefined searchoptions.sopt and undefined options of searching options prmSearch of navGrid the behavior which you described will be used.
So you can use for example navGrid in the form
$('#grid').jqGrid('navGrid', '#pager',
{refreshstate: 'current', add: false, edit: false, del: false}, {}, {}, {},
{sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni']}
);
Another possibility is to define the searchoptions.sopt directly for the 'date' column:
{name: 'date', index: 'date', width: 90, align: "center", editrules: {required: true},
searchoptions: {sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge']}}
You can include all operation which you want to have for the corresponding column depend on the type of the data inside.
What I really recommend you to do is to use column templates. In the projects which I developed for the customers I define in one JavaScript file which I include in all pages different templates for different types of data. For example
var initDate = function (elem) {
$(elem).datepicker({
dateFormat: 'dd-M-yy',
autoSize: true,
changeYear: true,
changeMonth: true,
showButtonPanel: true,
showWeek: true
});
},
dateTemplate = {width: 80, align: 'center', sorttype: 'date',
formatter: 'date', formatoptions: { newformat: 'm/d/Y' }, datefmt: 'm/d/Y',
editoptions: {date: true, dataInit: initDate },
searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'], dataInit: initDate }};
If you have defined the dateTemplate variable you can use it like
{name:'date', index:'date', editrules: {required: true}, template: dateTemplate }
Related
I am new to using jqgrid and what I try to do is that a specific id cannot edit the record by placing the status sold
here an example of the condition that I try to apply
if(session_level == 9){
{name:'status', index:'status', width:150, formatter: editexample, editable:true, stype: 'select', edittype:'select',
editoptions: {value: {'':'','New':'New','Cancelled':'Cancelled'} }, search: true,
searchoptions:{ sopt:['eq'], value: {'': 'Select', '':'', 'New':'New','Cancelled':'Cancelled'} }
},
}else
{name:'status', index:'status', width:150, formatter: editexample, editable:true, stype: 'select', edittype:'select',
editoptions: {value: {'':'','New':'New','Sold':'Sold','Cancelled':'Cancelled'} }, search: true,
searchoptions:{ sopt:['eq'], value: {'': 'Select', '':'', 'New':'New','Sold':'Sold','Cancelled':'Cancelled'} }
},
I'm not sure that I understand correct the question, but you can simple do it like this
var my_object = {'': 'Select', '':'', 'New':'New','Cancelled':'Cancelled'};
if(session_level == 9){
my_object['Sold']= 'Sold';
}
jqGrid({
....
colModel[
...
{name:'status', index:'status', width:150, formatter: editexample, editable:true, stype: 'select', edittype:'select',
editoptions: {value: my_object }, search: true,
searchoptions : { sopt:['eq'], value: my_object } }
...
]
});
in case this is a JavaScript. In case of PHP or other server side language you should do it in appropriate way
Is there a way to increase the size of the textbox fields in the advanced searching of jqgrid. The final textbox is squished for some reason. I have inserted an image to show this.
Here is the code
grid2 = $('#BillInformation').jqGrid({
...
{ name: 'DOS_From', index: 'DOS_From', width: 150, align: 'center',
searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'],
dataInit: function (elem) {
$(elem).datepicker({
showButtonPanel: true, changeMonth: true, changeYear: true,
showAnim: 'drop'
})
}
}
},
...
});
You can define the size attribute of the textbox fields from the Advanced Searching dialog by adding the corresponding property of the searchoptions option of the colModel. For example:
searchoptions: {size: 20}
I have tried hidden: true, width: 0, display: false but still I see the column in the grid. Than I tried
myGrid.jqGrid('hideCol', ["Type"]);
issue 1:
which is working and column is hidden but once I show collapsed rows than this column is again visible.
issue 2:
I have groupCollapse: true . When I uncollapse and do the sorting than all the rows collapsed again.
Problem:
Collapse/UnCollapse the hidden column shouldn't visible.
When sorting rows collapse.
var myGrid = $('#list');
myGrid.jqGrid({
url: '/Admin/DynamicGridData/',
datatype: 'json',
mtype: 'POST',
colNames: ['Id', 'Date', 'First Name', 'Last Name', 'Email Address', 'Hidden'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, align: "center", editable: false, editoptions: { readonly: true }, key: true, sorttype: "int", searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge']} },
{ name: 'DateEdited', index: 'DateEdited', width: 90, sorttype: "date", formatter: "date" },
{ name: 'FirstName', index: 'FirstName', width: 120, searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge']} },
{ name: 'LastName', index: 'LastName', width: 120, searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge']} },
{ name: 'Email', index: 'Email', width: 300, searchoptions: { sopt: ['cn', 'nc', 'bw', 'bn', 'eq', 'ne', 'ew', 'en', 'lt', 'le', 'gt', 'ge']} },
{ name: 'Type', index: 'Type', hidden: true, width: 0, display: false, search: false }
],
height: 'auto',
autowidth: true,
rownumbers: true,
rowNum: 30,
rowList: [10, 20, 30],
pager: '#pager',
sortname: 'Id',
viewrecords: true,
sortorder: "asc",
multiselect: true,
altRows: true,
altclass: 'myAltRowClass',
caption: "Master Grid",
jsonReader: { cell: "" },
grouping: true,
groupingView: { groupField: ['Type'],
groupColumnShow: [true],
groupText: ['<b>{0} - {1} Record(s)</b>'],
groupCollapse: false,
groupOrder: ['desc']
}
});
myGrid.jqGrid('navGrid', '#pager', { add: false, edit: false, del: true }, {}, {},
{ },
{ multipleSearch: true, overlay: false });
myGrid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: 'cn' });
myGrid.jqGrid('navButtonAdd', '#pager', { caption: "Filter", title: "Toggle Searching Toolbar", buttonicon: 'ui-icon-pin-s', onClickButton: function () { myGrid[0].toggleToolbar(); } });
myGrid[0].toggleToolbar();
myGrid.jqGrid('hideCol', ["Type"]);
You can use either
myGrid.jqGrid('hideCol', "Type");
instead of myGrid.jqGrid('hideCol', ["Type"]); or use
groupColumnShow: [false]
instead of groupColumnShow: [true] because you want hide the column on which you do grouping.
How I can make all the columns of jqgrid not resizable? Currently I think every column I've to specify the property { resizable:false }. Is there anyway I can specify for the entire grid?
Starting with version 3.8.2 jqGrid supports one very useful feature: column templates. (It's probably not quite correct from me to praise the feature because the feature was introduced on my own suggestion :-)). The feature is still not really documented, but it can be used very easily.
I explain it on an example. If you define additional jqGrid parameter
cmTemplate:{resizable:false}
then your problem will be solved.
If you have more properties which are common in all columns of colModel items, for example align:'center' the cmTemplate will help you also (cmTemplate:{resizable:false, align:'center'}). In jqGrid 3.8.2 was small bug in priority of template settings relatively to settings from colModel, but the bug is fixed in jqGrid 4.0.0. So the properties from cmTemplate can be interpret just as default values for colModel items.
One more version of usage jqGrid column template is in the form:
var myDateTemplate = {sorttype:'date', formatter:'date',
formatoptions: {newformat:'m/d/Y'}, datefmt: 'm/d/Y',
align:'center', width:80 }
$("list").jqGrid({
colModel: [
...
{name:'column1': template:myDateTemplate},
{name:'column2': template:myDateTemplate, width:90},
...
]
...
});
In the way you can define some templates (like myDateTemplate) and use there in many places in your grid (or gids). With respect of the feature you can make your code shorter, better readable and easily changeable.
Template works great for me:
{ name: 'quantity_warehouse', index: 'quantity_warehouse', template: intColTemplate, width: '70' },
{ name: 'status', index: 'status', align: 'left', template: stringColTemplate, width: '90' },
{ name: 'snapshot_at', index: 'snapshot_at', template: dateColTemplate },
{ name: 'applied_at', index: 'applied_at', template: dateColTemplate },
JS:
var dateColTemplate = { align: 'left', search: true, stype: 'text', width: '70', datefmt: 'm/d/y', formatter: 'date', formatoptions: { srcformat: 'm/d/y', newformat: 'm/d/Y' }, sorttype: 'date', searchrules: { required: true, date: true }, searchoptions: { sopt: ['eq', 'ge', 'le'],
dataInit: function (el) {
$(el).datepicker({ changeYear: true, changeMonth: true, showButtonPanel: true });
}
}
};
var intColTemplate = { align: 'left', search: true, stype: 'text', searchoptions: { sopt: ['eq', 'ge', 'le']} };
var stringColTemplate = { align: 'left', search: true, stype: 'text', searchoptions: { sopt: ['bw', 'cn']} };
I am trying to add the search bar with jquery.jqgrid.js after trying several methods this method was the only one that did not give me an error but neither does it show my search toolbar, can someone have a look and see if I missing anything??
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
url: '/Home/DynamicGridData/',
datatype: 'json',
mtype: 'POST',
colNames: ['Edit', 'AlertId', 'Policy', 'PolicyRule', 'Alert Status',
'Alert Code', 'Message', 'Category'],
colModel: [
{ name: 'Edit', edittype: 'select', formatter: 'showlink' },
{ name: 'AlertId', index: 'AlertId', sortable: true, sorttype: 'int',
autoFit: true, align: 'left', hidden: true },
{ name: 'Policy', index: 'Policy.Name', sortable: true, sorttype: 'text',
autoFit: true, searchoptions: { sopt: ['eq', 'ne', 'cn'] },
align: 'left' },
{ name: 'Policy Rule', index: 'PolicyRule', sortable: true,
sorttype: 'text', autoFit: true, sorttype: 'text',
searchoptions: { sopt: ['eq', 'ne', 'cn'] }, align: 'left' },
{ name: 'Alert Status', index: 'AlertStatus.status', sortable: true,
sorttype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn'] },
autoFit: true, align: 'left' },
{ name: 'Alert Code', index: 'Code', sortable: true, sorttype: 'text',
align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn'] },
autoFit: true },
{ name: 'Message', index: 'Message', sortable: true, sorttype: 'text',
align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn'] },
autoFit: true },
{ name: 'Category', index: 'Category.name', sortable: true,
sorttype: 'text', align: 'left', autoFit: true,
searchoptions: { sopt: ['eq', 'ne', 'cn'] }}],
pager: $("#pager"),
rowNum: 10,
rowList: [10, 60, 100],
scroll: true,
sortname: 'AlertId',
sortorder: 'asc',
viewrecords: true,
imgpath: '/scripts/themes/basic/images',
caption: 'my name',
gridComplete: function() {
var objRows = $("#list tr");
var objHeader = $("#list.jqgfirstrow td");
if (objRows.length > 1) {
var objFirstRowColumns = $(objRows[1]).children("td");
for (i = 0; i < objFirstRowColumns.length; i++) {
$(objFirstRowColumns[i]).css("width",
$(objHeader[i]).css("width"));
}
}
}
});
});
$("#list").jqGrid('navGrid','#pager',
{edit:true,add:true,del:true,search:true,refresh:true});
$("#list").jqGrid('navButtonAdd',"#pager",
{caption:"Toggle",title:"Toggle Search Toolbar",
buttonicon :'ui-icon-pin-s',
onClickButton:function() {
$("#list")[0].toggleToolbar()
} });
$("#list").jqGrid('navButtonAdd',"#pager",
{ caption: "Clear", title: "Clear Search",
buttonicon :'ui-icon-refresh',
onClickButton:function(){
$("#list")[0].clearToolbar()
} });
jQuery("#list").jqGrid('filterToolbar');
After the improving of the format of your code one can see your main error: you call navGrid, navButtonAdd and filterToolbar outside of jQuery(document).ready. If you move it inside the jQuery(document).ready you will see immediately the searching toolbar: see here.
You code has other small problems:
variable i inside gridComplete should be declared to be local and not global variable.
You should remove deprecated parameter imgpath.
You use many options of colModel parameters with default values like sortable:true, sorttype: 'text', align: 'left' and so on. It makes only the code longer, slowly and more difficult to read. I recommend you to look in the part of documentation which describes colModel parameters and remove default properties.
The sorttype property which you use will not work in case of usage datatype: 'json' without loadonce:true. So you should decide either you use server based sorting, paging and filtering/searching and you should better remove in the case sorttype properties or you should use loadonce:true, but the grid contain should be loaded at once at the first request to the server.
There are no autoFit column property.