I have a single page ASP.Net web forms application. And lots of grids. In my application, there is some links to hide or show grids. The problem is, when i start the application, the pagination of the displayed grid is working properly. (I tried this for each grid). But when I Click the link for hide a grid and show another grid, paging does not working. The grid initialization is;
$('#tblApplicationSettings').jqGrid({
url: cms.util.getAjaxPage(),
cellLayout: cms.theme.list.cellLayout,
hoverrows: false,
forceFit: true,
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "",
id: "0"
},
width: 900,
height: 400,
datatype: 'local',
colNames: ['SettingId',
'Description',
'Name',
'Value',
'ServerId',
'IsReadOnly',
''
],
colModel: [
{
name: 'SettingId',
index: 'SettingId',
hidden: true
},
{
name: 'Description',
index: 'Description',
search: false,
editable: true,
sortable: false,
width: 150,
inlineEditable: true
},
{
name: 'Name',
index: 'Name',
search: false,
editable: false,
sortable: false,
width: 150,
inlineEditable: false
},
{
name: 'Value',
index: 'Value',
search: false,
editable: true,
sortable: false,
width: 250,
inlineEditable: true,
},
{
name: 'ServerId',
index: 'ServerId',
search: false,
editable: true,
sortable: false,
width: 150,
formatter: 'select',
edittype: 'select',
editoptions: {
value: options,
},
inlineEditable: true
},
{
name: 'IsReadOnly',
index: 'IsReadOnly',
hidden: true
},
{
name: 'JsUsage',
index: 'JsUsage',
search: false,
editable: true,
sortable: false,
width: 150,
inlineEditable: true
},
],
onSelectRow: function (id) {
if (id && id !== lastSelection) {
jQuery('#grid').jqGrid('restoreRow', lastSelection);
lastSelection = id;
}
var columnModel = $('#grid').getGridParam('colModel');
var colNames = new Array();
$.each(columnModel, function (index, column) {
colNames.push(column.name);
if (isReadOnly || !column.inlineEditable) {
column.editable = false;
}
else {
column.editable = true;
}
if (column.edittype == "select") {
column.editoptions.dataEvents = [{
type: 'change',
fn: function (e) {
var newServerId = $(this).val();
that.isServerIdChanged = true;
if (newServerId == "null") {
}
}
}]
}
});
var row = $('#grid').getRowData(id);
var isReadOnly = row.IsReadOnly == "true" ? true : false;
if (isReadOnly) {
alert("row is not editable");
return null;
}
jQuery("#grid").jqGrid('editRow', id, {
keys: true,
extraparam: {
dataType: 'updateSetting',
colNames: JSON.stringify(colNames),
settingName: row.Name,
settingId: row.SettingId
},
successfunc: function (result) {
$("#grid").trigger('reloadGrid');
}
});
},
editurl: '/Ajax.ashx',
rowNum: 25,
direction: "ltr",
scroll: 1,
gridview: true,
pager: '#divPager',
viewrecords: true,
});
$('#grid').setGridParam({ datatype: "json", postData: { dataType: 'getSettings' } });
$('#grid').jqGrid('navGrid', '#divPager', { edit: false, add: false, del: false, search: false, refresh: false });
$('#grid').trigger('reloadGrid');
like this for all grids. I need tips or helps. Thanks.
Related
am using JQGrid and enabled Search to true . everything is working fine.
scenario: there are two budget column one is for footer total and another is for column
$("#BudgetGrid").jqGrid({
datatype: 'local',
data: JSON.parse($('#JsonData').val()),
colModel: [
{
name: 'BudgetId',
hidden: true,
classes: 'budgetid'
},
{
name: 'Month',
hidden: true
},
{
name: 'MonthInWords',
resizable: true,
//align: 'center',
label: 'Month',
ignoreCase: true
},
{
name: 'Budget',
resizable: true,
align: 'center',
label: 'Budget',
ignoreCase: true,
formatter: function (cellvalue, options, rowObject, rowid) {
return '<input type="textbox" class="form-control number" id="budget" value=\"' + rowObject.Budget + '\"></input>';
}
},
{
name: 'Budget',
resizable: true,
label: 'Budget',
ignoreCase: true,
hidden: true,
sorttype: 'number',
summaryType: 'sum',
formatter: 'integer',
formatoptions: {
decimalSeparator: '.', decimalPlaces: 2, suffix: '', thousandsSeparator: ',', prefix: ''
}
}
],
loadonce: true,
pager: "#BudgetGridPager",
viewrecords: true,
ignoreCase: true,
rowNum: 12,
footerrow: true,
userDataOnFooter:true,
gridComplete: function () {
var objRows = $("#BudgetGrid tbody tr");
var objHeader = $("#BudgetGrid tbody tr 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"));
}
}
}
, loadComplete: function (data) {
var $grid = $('#BudgetGrid');
//debugger;
$grid.jqGrid('footerData', 'set', { MonthInWords: "Total" });
$grid.jqGrid('footerData', 'set', { 'Budget': ($grid.jqGrid('getCol', 'Budget', false, 'sum')).toFixed(3) }, false);
}
});
$("#BudgetGrid").jqGrid('filterToolbar', {
autosearch: true,
stringResult: false,
searchOnEnter: false,
defaultSearch: "cn"
});
when i write hidden budget up search column search wont work
but when i write budget without hidden and next budget hidden , search works fine.
can anyone please say the reason behind it
Using simple built in functionality in Jqgrid where if you set the column property editable to true, it should pop up a form with that field text to be editable. Everything is fine except that the form coming up is not clickable.
Please point me what is wrong with this code before I resort to manual custom form.
$('#tblRecipes').jqGrid({
datatype: 'json',
mtype: 'POST',
url: 'ResultsEditorAjax/GetSampleRecipeValues',
editurl: 'ResultsEditorAjax/SaveSampleRecipeValue',
jsonReader: als.common.jqgrid.jsonReader('Analyte'),
colModel: [
{ name: 'Folderno', index: 'Folderno', sortable: false, hidden: true },
{ name: 'Ordno', index: 'Ordno', sortable: false, hidden: true },
{ name: 'Pcupno', index: 'Pcupno', sortable: false, hidden: true },
{ name: 'Taskcd', index: 'Taskcd', sortable: false, hidden: true },
{ name: 'Analyte', index: 'Analyte', label: 'Analyte', width: 10, sortable: false },
{ name: 'OldFinal', index: 'OldFinal', label: 'Old Value', width: 10, sortable: false },
{
name: 'NewFinal', index: 'NewFinal', label: 'New Value', width: 10,
sortable: false, editable: true, edittype: 'text',
editrules: { custom: true, custom_func: als.webview.analyteresults.validateRecipeValue }
},
{ name: 'Units', index: 'Units', label: 'Units', width: 5 },
{ name: 'Min', index: 'Min', sortable: false, hidden: true },
{ name: 'Max', index: 'Max', sortable: false, hidden: true },
{ name: 'Rounding', index: 'Rounding', sortable: false, hidden: true }
],
caption: '',
height: 200,
width: 400,
hidegrid: false,
shrinkToFit: true,
scroll: true,
rowNum: 10000,
viewrecords: true,
emptyrecords: '',
altRows: true,
pager: '#pagerRecipes',
onSelectRow:
function (rowId) {
},
gridComplete: function () {
},
loadComplete: function (data) {
}
}).jqGrid('navGrid', '#pagerRecipes', {
add: false,
edit: true,
del: false,
refresh: false,
search: false
},
{ // edit
editCaption: 'Edit Value',
mtype: 'POST',
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
resize: false,
modal: true,
// width: 680,
viewPagerButtons: false,
recreateForm: true,
closeAfterEdit: true,
closeOnEscape: true,
beforeInitData: function () {
// $('#grdQcGroups').jqGrid('setColProp', 'Id', { editable: false });
},
serializeEditData: function (postdata) {
// postdata.Id = postdata.id;
return postdata;
}
);
I have below setup jqgrid (v 4.6.0).
$(function () {
var JQGridDefaults = {
caption: '',
rowList: [10, 50, 100],
datatype: 'json',
height: '100%',
viewrecords: true,
mtype: 'GET',
colNames: ['Item Control No', 'Item Short Description', 'ID'],
colModel: [
{
name: 'ItemCode', index: 'ItemCode', search: true, width: 230, cellattr: makeCellContentWrap, searchoptions: {
sopt: ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc'],
},
searchrules: {required: true}
},
{
name: 'ItemShortDesc', index: 'ItemShortDesc', search: true, width: 300, cellattr: makeCellContentWrap, searchoptions: {
sopt: ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc'],
},
searchrules: {required: true }
}
//Hidden Fields - Start
{ name: 'ItemID', hidden: true, key: true }
//HiddenFields End
],
pager: '#GridPager',
rowNum: 10,
sortname: 'ItemCode',
sortorder: 'asc',
url: '/Items/List',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
userdata: "userdata",
subgrid: {
root: "rows",
repeatitems: false
}
},
//Sub Grid - Start
subGrid: true,
subGridBeforeExpand: function (pID, rowID) {
console.log("Before Expand");
var gridData = $(this).jqGrid('getRowData',rowID);
if (gridData.ItemCode == "") {
return false;
}
},
subGridUrl: '/Items/Details',
subGridModel: {
name: ['Revision', 'ItemCode'],
width: [50, 100],
align: ['center', 'center'],
mapping: ['Revision', 'ItemCode']
},
afterInsertRow: function (rowid, aData, rowelem) {
// Remove the subgrid plus button except for rows that have exceptions
if (aData.ItemCode == "") {
$('#' + rowid).children("td.sgcollapsed").unbind();
$('#' + rowid).children("td.sgcollapsed").html("");
}
}
//Sub Grid - END
};
var JQGridSearchDefaults = {
multipleSearch: true,
recreateFilter: true,
showQuery: true,
closeAfterSearch: true,
closeAfterReset: true,
searchOnEnter: true,
closeOnEscape:true,
width: 600
};
$('#Grid').jqGrid(JQGridDefaults).navGrid('#GridPager', { view: false, del: false, add: false, edit: false, refresh: true },
{},
{},
{},
JQGridSearchDefaults);
$('#Grid').jqGrid('setGridWidth', $('#Grid').parents('.main-content').width() - 2);
$(window).resize(function () {
clearTimeout(this.id);
this.id = setTimeout(function () {
$('#Grid').jqGrid('setGridWidth', $('#Grid').parents('.main-content').width() - 2);
}, 300);
});
});
The sub grid icon appears correctly but when I click on the Expand icon an empty row appears (no headers and no ajax call is sent)
does anyone have an idea on why the ajax call is not happening?
Note: I also tried to use 'subgridtype' parameter and define to make the service call that too did not make the Ajax call.
subgridtype: function (rowidparam) {
$.ajax({
url: '/Items/Details',
cache: false,
type: 'Get',
dataType: "json",
data: { id: rowidparam.ItemID }
}).done(function (data) {
$('#Grid')[0].subGridJson(data, rowidparam.id);
});
},
subgridtype must be string, for you try json
subgridtype: 'json'
I'm new to WebApi and I have problem with the received post parameters.
I want to populate jqgrid with data received from webapi controller method.
The grid code is as follows:
buildPostData: function (postData) {
var parameters = {
page: postData.page,
rows: postData.rows,
sidx: '',
sord: '',
_search: false,
searchField: '',
searchString: '',
searchOper: '',
filter: { groupOp: '', rules: [] }
};
$.extend(parameters, postData);
var data = {
parameters: parameters
};
return JSON.stringify(data);
}
bindGridAllData: function () {
var viewModel = this;
jQuery("#AllDataGrid").jqGrid({
url: 'api/DataApi/GetAllData',
datatype: 'json',
mtype: 'POST',
ajaxGridOptions: {
contentType: 'application/json; charset=utf-8'
},
serializeGridData: viewModel.buildPostData,
serializeRowData: function (data) {
return JSON.stringify(data);
},
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
colNames: ['DataId', 'Title', 'Description', 'Date', 'UserId', 'Name', 'Surname', 'PicturePath', 'NumberOfComments', ''],
colModel: [
{ name: 'DataId', index: 'DataId', width: 10, hidden: true, editable: false, sortable: false, key: true },
{ name: 'Title', index: 'Title', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{ name: 'Description', index: 'Description', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{ name: 'Date', index: 'Date', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{ name: 'UserId', index: 'UserId', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{ name: 'Name', index: 'Name', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{ name: 'Surname', index: 'Surname', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{ name: 'PicturePath', index: 'PicturePath', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{ name: 'NumberOfComments', index: 'NumberOfComments', width: 10, editable: false, align: 'left', sortable: true, hidden: true },
{
name: 'DataInformation', index: 'DataInformation', width: 200, editable: false, align: 'left', sortable: true, formatter: function (cellvalue, options, rowObject) {
var template = $('<div data-bind="template: { name: \'DataRecord\', data: DataRecord, ajax: { async: false } }"></div>');
var data = { DataRecord: rowObject };
ko.applyBindings(data, template[0]);
return template.html();
}
}
],
height: '100%',
width: 900,
pager: '#resultGridAllDataPager',
rowNum: 10,
rownumbers: false,
scroll: false,
sortname: 'Date',
sortorder: "asc",
gridview: true,
hoverrows: false,
viewrecords: true,
cmTemplate: { title: false },
loadComplete: function () {
}
});
}
And the WebApi method is:
[HttpPost]
public JQGridData GetAllData(JQGridSearchParameters parameters)
{
using (dataMKbazaEntities context = new dataMKbazaEntities())
{
JQGridData grid = new JQGridData();
var allData = context.ispolniSITEpodatoci().ToList();
List<object> data = new List<object>();
foreach (var ad in allData)
{
data.Add(new {
DataId=ad.podatokID,
Title=ad.naslov,
Description=ad.opis,
Date=ad.datum,
UserId=ad.idKORISNIK,
Name=ad.ime,
Surname=ad.prezime,
PicturePath=ad.slika,
NumberOfComments=ad.brojKOMENTARI
});
}
grid.rows = data;
grid.page = parameters.page;
grid.records = data.Count;
grid.total = (int)Math.Ceiling((float)data.Count / (float)parameters.rows);
return grid;
}
}
When sending data, parameters have values defined from buildPostData method but when received in WepApi controller method they are null.
I have tried with [FromBody] in webapi method but with no success.
Status code in http request is 200 OK
Make sure of the following:
Your raw request has the Content-Type header. Looking at your client code you seem to be sending it, but just wanted to make sure that it is indeed sent over the wire. Web API had a bug where if you do not send Content-Type header, since we do not know which formatter to deserialize the content, we default to the default value of the C# type. In this case it could be 'null'. This has been fixed later and is not yet publicly available though.
Have the following check to see any model state errors:
if (!ModelState.IsValid)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));
}
Am using jqgrid, loading data once, sorting and filtering locally and doing a refresh after each update/insert/delete. It works fine, besides that if I am using a filter (on top of grid), the filter remains the same after refresh, but the filter is not re-applied on the newly loaded data.
I have tried to call mygrid[0].triggerToolbar() after reloading grid with trigger('reloadGrid'), but there is no effect.
Thanks for any help or pointers :-)
Code below:
var lastsel;
var mygrid;
var currentLang;
//setup grid with columns, properties, events
function initGrid(lang, productData, resellerData, resellerSearchData) {
mygrid = jQuery("#list2").jqGrid({
//data loading settings
url: '/public/Gadgets/LinkGadget/ProductLinks/' + lang,
editurl: "/public/Gadgets/LinkGadget/Edit/" + lang,
datatype: "json",
mtype: 'POST',
jsonReader: {
root: "rows",
cell: "",
page: "currpage",
//total: "totalrecords",
repeatitems: false
},
loadError: function (xhr, status, error) { alert(status + " " + error); },
//column definitions
colNames: ['Id', 'ProductId', 'Reseller Name', 'Link', 'Link Status'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, sortable: false, resizable: true, editable: false, search: false, key: true, editrules: { edithidden: true }, hidden: true },
{ name: 'ProductId', index: 'ProductId', width: 190, sortable: true, sorttype: 'text', resizable: true, editable: true, search: true, stype: 'select', edittype: "select", editoptions: { value: productData }, editrules: { required: true} },
{ name: 'ResellerName', indexme: 'ResellerName', width: 190, sortable: false, sorttype: 'text', resizable: true, editable: true, search: true, stype: 'select', edittype: "select", editoptions: { value: resellerData }, editrules: { required: true }, searchoptions: { sopt: ['eq'], value: resellerSearchData} },
{ name: 'Link', index: 'Link', width: 320, sortable: true, sorttype: 'text', resizable: true, editable: true, search: true, edittype: "textarea", editoptions: { rows: "3", cols: "50" }, editrules: { required: true }, searchoptions: { sopt: ['cn']} },
{ name: 'LinkStatus', index: 'LinkStatus', width: 100, sortable: false, resizable: true, editable: false, search: false, formatter: linkStatusFormatter}],
//grid settings
//rowList: [10, 25, 50],
rowNum: 20,
pager: '#pager2',
sortname: 'ProductId',
sortorder: 'asc',
height: '100%',
viewrecords: true,
gridview: true,
loadonce: true,
viewsortcols: [false, 'vertical', true],
caption: " Product links ",
//grid events
onSelectRow: function (id) {
if (id && id !== lastsel) {
if (lastsel == "newid") {
jQuery('#list2').jqGrid('delRowData', lastsel, true);
}
else {
jQuery('#list2').jqGrid('restoreRow', lastsel);
}
jQuery('#list2').jqGrid('editRow', id, true, null, afterSave); //reload on success
lastsel = id;
}
},
gridComplete: function () {
//$("#list2").setGridParam({ datatype: 'local', page: 1 });
$("#pager2 .ui-pg-selbox").val(25); //changing the selected values triggers paging to work for some reason
}
});
//page settings
jQuery("#list2").jqGrid('navGrid', '#pager2',
{ del: false, refresh: false, search: false, add: false, edit: false }
);
//refresh grid button
jQuery("#list2").jqGrid('navButtonAdd', "#pager2", { caption: "Refresh", title: "Refresh grid", buttonicon: 'ui-icon-refresh',
onClickButton: function () {
reload();
}
});
//clear search button
jQuery("#list2").jqGrid('navButtonAdd', "#pager2", { caption: "Clear search", title: "Clear Search", buttonicon: 'ui-icon-refresh',
onClickButton: function () {
mygrid[0].clearToolbar();
}
});
//add row button
jQuery("#list2").jqGrid('navButtonAdd', '#pager2', { caption: "New", buttonicon: 'ui-icon-circle-plus',
onClickButton: function (id) {
var datarow = { Id: "newid", ProductId: "", ResellerName: "", Link: "" };
jQuery('#list2').jqGrid('restoreRow', lastsel); //if editing other row, cancel this
lastsel = "newid"; // id;
var su = jQuery("#list2").addRowData(lastsel, datarow, "first");
if (su) {
jQuery('#list2').jqGrid('editRow', lastsel, true, null, afterSave); //reload on success
jQuery("#list2").setSelection(lastsel, true);
}
},
title: "New row"
});
//delete row button
jQuery("#list2").jqGrid('navButtonAdd', "#pager2", { caption: "Delete", title: "Delete row", buttonicon: 'ui-icon-circle-minus',
onClickButton: function () {
if (lastsel) {
if (confirm('Are you sure you want to delete this row?')) {
var url = '/public/Gadgets/LinkGadget/Edit/' + currentLang;
var data = { oper: 'del', id: lastsel };
$.post(url, data, function (data, textStatus, XMLHttpRequest) {
reload();
});
lastsel = null;
}
else {
jQuery("#list2").resetSelection();
}
}
else {
alert("No row selected to delete.");
}
}
});
jQuery("#list2").jqGrid('filterToolbar');
}
//Used by initGrid - formats link status column by adding button
function linkStatusFormatter(cellvalue, options, rowObject) {
if (rowObject.Id != "newrow")
return "<input style='height:22px;width:90px;' type='button' " + "value='Check link' " + "onclick=\"CheckLink(this, '" + rowObject.Id + "'); \" />";
else
return "";
}
//Used by initGrid - reloads grid
function reload() {
//jqgrid setting "loadonce: true" will reset datatype from json to local after grid has loaded. "datatype: local"
// does not allow server reloads, therefore datatype is reset before trying to reload grid
$("#list2").setGridParam({ datatype: 'json' }).trigger('reloadGrid');
//mygrid[0].clearToolbar();
lastsel = null;
//Comments: after reload, toolbar filter is not applied to refreshed data. Tried row below without luck
//mygrid[0].triggerToolbar();
}
//after successful save, reload grid and deselect row
function afterSave() {
reload();
}
Your data is not getting re binded to the grid after save/update delete