The first click on editing a row works great, but after closing the dialog and clicking on another row edit button, it throws an exception (in subject).
When debugging I saw in jquery.min.js "#" sign crashes, my guess it somehow gets this invalid character. code:
$("#jqgrid").jqGrid({
datatype: "local",
mtype: 'GET',
colNames: ['Pic', 'Category', 'Order', 'Name', 'Description', 'Full Price', 'Price', 'Is Pack', 'Is Active', 'Is Shipment', 'Is Pack Only', 'Attributes', 'Sites', 'Call Centers', ''],
colModel: [
{ name: 'PictureUrl', index: 'PictureUrl', width: 40, formatter: imageFormatter, align: 'center' },
{ name: 'CategoryID', index: 'CategoryID', width: 60, editable: true, editoptions: { size: 30, value: getProductCategories }, edittype: "select" },
{ name: '', index: 'ProductID', width: 40, editable: true, editoptions: { size: 30} },
{ name: 'ProductName', index: 'ProductName', width: 40, editable: true, editoptions: { size: 30} },
{ name: 'ProductDesription', index: 'ProductDesription', width: 40, editable: true, editoptions: { size: 30} },
{ name: 'FullPrice', index: 'FullPrice', width: 40 },
{ name: 'ActualPrice', index: 'ActualPrice', width: 40 },
{ name: 'IsPackage', index: 'IsPackage', width: 40, editable: true, editoptions: { size: 30, value: "Yes:No" }, edittype: "checkbox" },
{ name: 'IsActive', index: 'IsActive', width: 40, editable: true, editoptions: { size: 30, value: "Yes:No" }, edittype: "checkbox" },
{ name: 'IsShipment', index: 'IsShipment', width: 40, editable: true, editoptions: { size: 30, value: "Yes:No" }, edittype: "checkbox" },
{ name: 'IsPackageOnly', index: 'IsPackageOnly', width: 40, editable: true, editoptions: { size: 30, value: "Yes:No" }, edittype: "checkbox" },
{ name: '', index: '', width: 40 }, //attributes
{name: 'ProductInSites', index: 'ProductInSites', width: 40, editable: true, edittype: "textarea", editoptions: { rows: "2", cols: "35"} },
{ name: ' ', index: '', width: 40, align: 'center', editable: true, edittype: "textarea", editoptions: { rows: "2", cols: "35"} }, //callcentre
{ name: ' ', index: '', width: 40, align: 'center', formatter: updatebutton }, //button
],
rowNum: 20,
rowList: [10, 20, 30],
pager: '#jqpager',
sortname: 'OrderDate',
viewrecords: true,
sortorder: "desc",
caption: "Shipment Report",
autowidth: true,
height: "100%",
loadtext: "Loading...",
editurl: "ProductsList.ashx?actiontype=3"
});
You use name: '' and name: ' ' in the definition of some columns in colModel. It is wrong. The name property must be unique name having no blanks or special characters.
Related
I am working in a Jqgrid and have encountered a problem. I have looked at many examples and read alot of documentation but can't seem to determine why only 1 search option appears in the column header as opposed to the others such as "ge" "le" "eq" etc?
This is my code:
jQuery("#jQGridDemo").jqGrid({
url: 'http://localhost:58404/JQGridHandler.ashx',
datatype: "json",
colNames: ['Property ID', 'Property Ref', 'Short Address', 'Scheme Code', 'Scheme Name', 'Property Type', 'Tenure Type', 'Status'],
colModel: [
{ name: 'PropertyID', index: 'PropertyID', width: 70, align: "left", searchoptions: {sopt: ["ge","le","eq"]}, sortable: true},
{ name: 'PropertyRef', index: 'PropertyRef', width: 75, align: "left", stype: 'text', sortable: true},
{ name: 'ShortAddress', index: 'ShortAddress', width: 200, align: "center", search:true, stype: 'text', searchoptions: {sopt: ["cn","ge","le","eq"]}, sortable: true},
{ name: 'SchemeCode', index: 'SchemeCode', width: 80, align: "center", sortable: true },
{ name: 'SchemeName', index: 'SchemeName', width: 80, align: "center", stype: 'text', sortable: true },
{name: 'PropertyType',width: 80, align: "center",},
{ name: 'TenureType', index: 'TenureType', width: 80, align: "center", sortable: true },
{ name: 'Status', index: 'Status', width: 75, align: "center", sortable: true },
],
beforeProcessing: function (data) {
//Create the filters
getDropDownValues(data, 'PropertyType')
getDropDownValues(data, 'TenureType')
getDropDownValues(data, 'Status')
$(this).jqGrid('destroyFilterToolbar')
.jqGrid('filterToolbar', {
stringResult: true,
searchOperators: true
});
},
onSelectRow: function(id){
if(id && id!==lastsel2){
jQuery('#jQGridDemo').jqGrid('restoreRow',lastsel2);
jQuery('#jQGridDemo').jqGrid('editRow',id,true);
lastsel2=id;
}
},
height: 'auto',
width: 'auto',
rowNum: 30,
editable: true,
mtype: 'GET',
loadonce: true,
rowList: [30, 40, 50],
pager: '#jQGridDemoPager',
sortname: 'PropertyId',
viewrecords: true,
sortorder: 'desc',
caption: "Property Details",
editurl: 'http://localhost:58404/JQGridHandler.ashx'
});
I want filter on the data which comes dynamically in list format. If i
used SearchOptions event for that then it throws error of TypeError: Unable to read "stype" of Undefined or Null reference. Anyone can provide me solution for that. Grid model shown in below:
jQuery("#list2").jqGrid({
url: '/LocaleRate/LocaleRates',
datatype: "json",
colModel: [
{ name: 'Id', hidden: true },
{
name: 'SourceLocaleId', index: 'SourceLocaleName', width: 130, align: "left", editable: true, edittype: "select", formatter: 'select', editoptions: { value: LocaleList }, editrules: { required: true , stype: 'select', searchoptions: { sopt: ['eq', 'ne'], value: LocaleList
},
{
name: 'LocaleId', index: 'LocaleName', width: 90, align: "left", editable: true, edittype: "select", formatter: 'select', editoptions: { value: LocaleList }, editrules: { required: true }, stype: "select", searchoptions: { value: LocaleList }
},
{
name: 'CompanyId', index: 'CompanyName', editable: true, width: 100, editable: true, edittype: "select", formatter: 'select',
editoptions: {value: CompanyList}, editrules: { required: true},
stype: "select", searchoptions: { value: CompanyList }
},
{ name: 'VDBID', id: 'VDBID', editable: true, width: 90, editrules: { required: true }, editoptions: { readonly: "readonly" } },
{
name: 'CurrencyId', index: 'CurrencyName', width: 100, editable: true, edittype: "select", formatter: 'select', editoptions: { value: CurrencyList }, editrules: { required: true },
stype: "select", searchoptions: { value: CurrencyList }
},
{ name: 'HourRate', id: 'HourRate', editable: true, width: 130, editrules: { required: true } },
{ name: 'PageRate', id: 'PageRate', editable: true, width: 90, editrules: { required: true } },
{ name: 'WordRateExact', id: 'WordRateExact', editable: true, width: 130, editrules: { required: true } },
{ name: 'WordRateDuplicate', id: 'WordRateDuplicate', editable: true, width: 140, editrules: { required: true } },
{ name: 'WordRateFuzzy', id: 'WordRateFuzzy', editable: true, width: 130, editrules: { required: true } },
{ name: 'WordRateNew', id: 'WordRateNew', editable: true, width: 90, editrules: { required: true } },
{ name: 'MinimumPageCount', id: 'MinimumPageCount', editable: true, width: 130, editrules: { required: true } },
{ name: 'MinimumWordCount', id: 'MinimumWordCount', editable: true, width: 130, editrules: { required: true } },
{ name: 'WordRateExactComplex', id: 'WordRateExactComplex', editable: true, width: 150, editrules: { required: true } },
{ name: 'MinimumCharge', id: 'MinimumCharge', editable: true, width: 90, editrules: { required: true } },
{ name: 'WordRateDuplicateComplex', id: 'WordRateDuplicateComplex', editable: true, width: 150, editrules: { required: true } },
{ name: 'WordRateFuzzyComplex', id: 'WordRateFuzzyComplex', editable: true, width: 90, editrules: { required: true } },
{ name: 'WordRateNewComplex', id: 'WordRateNewComplex', editable: true, width: 90, editrules: { required: true } },
{ name: 'FirstProofRate', id: 'FirstProofRate', editable: true, width: 90, editrules: { required: true } },
{ name: 'WordRateHighFuzzy', id: 'WordRateHighFuzzy', editable: true, width: 90, editrules: { required: true } },
{ name: 'WordRateHighFuzzyComplex', id: 'WordRateHighFuzzyComplex', editable: true, width: 90, editrules: { required: true } },
{ name: 'DTPVendorHourRate', id: 'DTPVendorHourRate', editable: true, width: 90, editrules: { required: true } },
{ name: 'DTPVendorPageRate', id: 'DTPVendorPageRate', editable: true, width: 90, editrules: { required: true } },
{ name: 'VDBPriceLineID', id: 'VDBPriceLineID', editable: true, width: 90, editrules: { required: true } },
{ name: 'MTRate', id: 'MTRate', editable: true, width: 90, editrules: { required: true } },
{ name: 'DTPClientHourRate', id: 'DTPClientHourRate', editable: true, width: 90, editrules: { required: true } },
{
name: 'IsActive', editable: true, width: 40, edittype: "checkbox", editoptions: { value: "True:False" }
}
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager',
loadonce: true,
sortname: 'id',
height: "auto",
width: 2000,
viewrecords: true,
sortorder: "desc",
caption: "JSON Example",
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
id: "0"
},
autowidth: true,
});
jQuery("#list2").jqGrid('filterToolbar', {
stringResult: true,
searchOnEnter: false,
});
With Reference to above code, I want filters on SourceLocaleId, LocaleID, CompanyId & CurrencyId fields which has dynamic data.
Here I have replaced index value of each column which has dynamic data in list manner from 'SourceLocaleName' to 'SourceLocaleId'.
I using jqgrid filtertoolbar. I'm having some 4 select filter in that. When i tried to select one of the values in any select box i'm getting the following error.
Unable to get property 'stype' of undefined or null reference
Is there any general error or missing value that i have done anywhere in my code.
//Code:
Sample of colModel:
colModel:
jQuery.ajax({
url: 'ManageCandidateDetails.aspx/GetAllCandidateDetails',
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
// debugger;
genericResult = $.parseJSON(data.d);
// debugger;
jQuery("#CandidateDetailsGrid").jqGrid({
data: genericResult.candidateDetails,
datatype: "local",
// colNames: ['CandidateId', 'Email', 'Name'],
//colModel: [{ name: 'CandidateId', index: 'CandidateId', width: 75}, { name: 'Email', index: 'Email', width: 75 }, { name: 'Name', index: 'Name', width: 100}],
colNames: ['CandidateId', 'Name', 'Email', 'DOB', 'Gender', 'Qualification', 'Department', 'OtherQual', 'OtherDept', 'Exp(Years)', 'Exp(Months)', 'Mobile', 'Country', 'State', 'City', 'ZipCode', 'FilePath', 'Sel.Status', 'CreatedDate', 'ModifiedDate', 'ModifiedBy', 'Status', 'LastLoginTime'],
colModel: [{ name: 'CandidateId', index: 'CandidateId', width: 75, editable: true },
{ name: 'Name', index: 'Name', width: 100, editable: true },
{ name: 'Email', index: 'Email', width: 75, editable: true },
{ name: 'DOB', index: 'DOB', width: 50, editable: true, searchoptions: { dataInit: newDatePick }, editoptions: { dataInit: newDatePick} },
{ name: 'Gender', index: 'Gender', width: 50, editable: true },
{ name: 'Qualification', index: 'Qualification', width: 75, editable: true, stype: 'select', editoptions: { value: ":All;" + genericResult.qualification} },
{ name: 'Department', index: 'Department', width: 75, editable: true, stype: 'select', editoptions: { value: ":All;" + genericResult.department} },
{ name: 'OtherQual', index: 'OtherQual', width: 75, editable: true },
{ name: 'OtherDept', index: 'OtherDept', width: 75, editable: true },
{ name: 'ExperienceYears', index: 'ExperienceYears', width: 75, editable: true },
{ name: 'ExperienceMonths', index: 'ExperienceMonths', width: 75, editable: true },
{ name: 'Mobile', index: 'Mobile', width: 100, editable: true },
{ name: 'Country', index: 'Country', width: 100, editable: true, stype: 'select', formatter: 'select', edittype: 'select',
searchoptions: {
value: allCountries, stype: 'select'
},
editoptions: {
value: allCountries,
dataInit: removeTheOptionAll,
dataEvents: [
{ type: "change", fn: function (e) { changeStateSelect($(e.target).val(), e.target); } }
]
}
},
{ name: 'state', index: 'state', width: 100, formatter: "select", stype: "select",
editable: true, edittype: "select",
editoptions: { value: allStates, dataInit: removeTheOptionAll },
searchoptions: { value: allStates }
},
{ name: 'City', index: 'City', width: 50, editable: true },
{ name: 'ZipCode', index: 'ZipCode', width: 50, editable: true },
{ name: 'FilePath', formatter: function () { return "<img src='../Images/error.png' alt='my image' />"; }, unformat: imageUnFormat, index: 'FilePath', width: 50 },
{ name: 'SelectedStatus', index: 'SelectedStatus', width: 75, edittype: 'checkbox', formatter: 'checkbox', editable: true, editoptions: { value: "1:Yes;0:No" }, stype: 'select', searchoptions: { sopt: ['eq'], value: "All:All;1:Yes;0:No"} },
{ name: 'CreatedDate', index: 'CreatedDate', width: 75, formatoptions: { srcformat: "ISO8601Long", newformat: "d/m/Y h:i A" },
searchoptions: { dataInit: datePick }, editoptions: { dataInit: datePick }
},
{ name: 'ModifiedDate', index: 'ModifiedDate', width: 75, formatoptions: { srcformat: "ISO8601Long", newformat: "d/m/Y h:i A" },
searchoptions: { dataInit: datePick }, editoptions: { dataInit: datePick }
},
{ name: 'Modifiedby', index: 'ModifiedBy', width: 75 },
{ name: 'Status', index: 'Status', width: 50, edittype: 'checkbox', editable: true, stype: 'select', searchoptions: { value: "All:All;1:Yes;2:No"} },
{ name: 'LastLoginTime', index: 'LastLoginTime', width: 75, formatoptions: { srcformat: "ISO8601Long", newformat: "d/m/Y h:i A" },
searchoptions: { dataInit: datePick, attr: { title: 'Select Date'} }, editoptions: { dataInit: datePick }
}],
rowNum: 10,
mtype: 'GET',
loadonce: true,
rowList: [10, 20, 30],
pager: '#CandidateDetailsGridPager',
sortname: 'CandidateId',
viewrecords: true,
caption: "Candidate Details",
ignoreCase: true,
gridview: true,
rownumbers: true
});
jQuery("#CandidateDetailsGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
$('#CandidateDetailsGrid').jqGrid('navGrid', '#CandidateDetailsGridPager',
{
edit: true,
add: true,
del: true,
search: true,
searchtext: "Search",
addtext: "Add",
edittext: "Edit",
deltext: "Delete"
},
{ // edit option
beforeShowForm: function (form) {
}
},
{ // add option
addcaption: 'Add Candidate Detail',
beforeShowForm: function (form) {
//debugger;
$("#myFormError").remove();
$('#tr_LastLoginTime', form).hide();
$('#tr_CandidateId', form).hide();
$('#tr_Modifiedby', form).hide();
$('#tr_ModifiedDate', form).hide();
$('#tr_CreatedDate', form).hide();
},
onclickSubmit: function (response, postData) {
debugger;
$("#FormError").text("");
$("<tr id='myFormError'><td colspan='2'><div style='background-color:green;color:white; font-weight:bold; width:100%;padding-left:5px;'>Success</div></td></tr>").insertAfter("#FormError");
}
}
);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
}
});
//Unformat the image during the edit.
function imageUnFormat(cellvalue, options, cell) {
return cellvalue
}
I load jqgrid with drop down values using onchange event.
But when i again choose some other value in drop down i need the jqgrid to show the corresponding values.
Here s how i load the jqgrid
function getGrid() {
var mOptometrist = $('#optOptometristList').val();// Drop down value
alert(mOptometrist);
//jQuery("#list").jqGrid().setGridParam({ url: 'Schedule.ashx?mOptometristId=' + mOptometrist + '' }).trigger("reloadGrid");
jQuery("#jQGridDemo").jqGrid({
url: 'Schedule.ashx?mOptometristId=' + mOptometrist + '',
datatype: "json",
colNames: ['Id', 'Day', 'Start Time', 'End Time', 'Interval', 'Session', "Patient", 'Slots', 'Room Number'],
colModel: [
{ name: 'SlNo', index: '_id', width: 20, stype: 'text', editable: true, editoptions: { disabled: true} },
{ name: 'DayOfWeek', index: 'Day', width: 150, stype: 'text', sortable: true, editable: true, edittype: "select", formatter: 'select', editoptions: { value: getAllSelectOptions()} },
{ name: 'StartTime', index: 'StartTime', width: 150, editable: true, formatter: 'date', formatoptions: { srcformat: 'u', newformat: 'H:i:s'} },
{ name: 'EndTime', index: 'EndTime', width: 60, editable: true, formatter: 'date', formatoptions: { srcformat: 'u', newformat: 'H:i:s'} },
{ name: 'Interval', index: 'Interval', width: 80, align: "right", editable: true },
{ name: 'Session', index: 'Session', width: 40, align: "right", editable: true },
{ name: 'PatientsPerSlot', index: 'Patient', width: 80, align: "right", editable: true },
{ name: 'Slots', index: 'Slots', width: 150, sortable: false, editable: true },
{ name: 'RoomID', index: 'RoomNumber', width: 100, sortable: false, editable: true }
],
rowNum: 10,
mtype: 'GET',
loadonce: false,
rowList: [10, 20, 30],
pager: '#jQGridDemoPager',
sortname: '_id',
viewrecords: true,
sortorder: 'desc',
caption: "List Employee Details",
editurl: 'Schedule.ashx?mOptometristId= ' + mOptometrist,
loadComplete: function () {
$("#jQGridDemo").setColProp('Day', { editoptions: { value: "1:Sunday;2:Monday;3:Tuesday"} });
}
});
You can use
url: "",
postData: {
mOptometristId: function () {
return $('#optOptometristList').val();
}
}
instead of
url: 'Schedule.ashx?mOptometristId=' + mOptometrist + ''
Inside of onchange event you need just call $("#jQGridDemo").trigger("reloadGrid");. See the answer for more details.
For some reason (unknown to me) the event 'formatCell' doesn't fire (no alert message shown). see code below:
$("#jqgrid").jqGrid({
datatype: "json",
colNames: ['CurrecncyID', 'Currency', 'Value', 'Calculated', 'Value', '%', 'Calculated'],
colModel: [
{ name: 'CurrecncyID', index: 'CurrecncyID', hidden: true, width: 40 },
{ name: 'CurrencyName', index: 'CurrencyName', width: 150 },
{ name: 'FullPrice', index: 'FullPrice', width: 100, editrules: { custom: true, custom_func: priceCheck }, editable: true, align: 'right', formatter: priceFormatter },
{ name: 'CalcFullPrice', index: 'CalcFullPrice', width: 100, align: 'right', formatter: priceFormatter },
{ name: 'ActualPrice', index: 'ActualPrice', width: 100, editrules: { custom: true, custom_func: priceCheck }, editable: true, align: 'right', formatter: priceFormatter },
{ name: 'Precent', index: 'Precent', width: 100, align: 'right', formatter: 'integer', formatoptions: { prefix: "% "} },
{ name: 'CalcActualPrice', index: 'CalcActualPrice', width: 100, align: 'right', formatter: priceFormatter },
],
onSelectRow: function (id) {
if (id && id !== lastsel) {
jQuery('#jqgrid').restoreRow(lastsel);
jQuery('#jqgrid').editRow(id, true);
lastsel = id;
}
},
formatCell: function (rowid, cellname, value, iRow, iCol) {
alert("before edit");
},
jsonReader: {
repeatitems: false
},
rowNum: 20,
rowList: [10, 20, 30],
pager: '#jqpager',
sortname: 'CurrecncyID',
viewrecords: true,
sortorder: "desc",
caption: "Prices List",
autowidth: true,
height: "100%",
loadtext: "Loading...",
editurl: "/handlers/myurl.ashx"
});`
There are three main editing modes used in jqGrid. The formatCell event is a part of the cell editing mode. It will be not fire in case of usage of editRow and restoreRow are the part of the inline editing mode. Probably you need use custom editable element in case of the usage of the inline editing mode.