load jqgrid via ajax to dialog search options dropdown don't work - ajax

When I use my jqgrid (v.4.6) on page evrything is ok.
When I load jqgrid via ajax to jquery dialog searchoptions dropdown list doesn't work for me.
In jqgrid search box searchoptions dropdown list doesn't work for me either.
$(document).ready(function(){
jQuery("#list_bs").jqGrid({
url:'some.php',
datatype: "json",
height: 450,
width: 1050,
colNames:['FirstName','Name','Date'],
colModel:[
{name:'FirstName',index:'FirstName', width:200, sorttype:'string', searchoptions:{sopt:['bw','bn','cn','ne','ew','en']}},
{name:'Name',index:'Name', width:200, sorttype:'string', searchoptions:{sopt:['bw','bn','cn','ne','ew','en']}},
{name:'Date',index:'Date', width:100, sorttype:'string', searchoptions:{sopt:['bw','bn','cn','ne','ew','en']}},
],
rowNum:50,
rowList : [20,30,50],
loadonce:false,
multiselect : false,
mtype: "GET",
shrinkToFit: false,
rownumbers: true,
gridview: true,
pager: '#pager',
sortname: 'Name',
viewrecords: true,
sortorder: "ASC",
toolbar: [true,"top"],
});
$("#list_bs").jqGrid('navGrid', '#pager_bs',
{
edit:false,
add:false ,
del:false,
},
{},
{},
{},
{
multipleSearch: true,
showQuery: true
}
......
)
});
jQuery("#list_bs").jqGrid('filterToolbar',{ searchOperators: true,stringResult:true, searchOnEnter: false, autosearch: true ,enableClear: false});

try like below this work for me.You have give data in the dropdown in its column model
{
name: 'Name', Name: 'Title', align: 'center', editable: true, editoptions: { readonly: 'readonly' },
stype: 'select',
searchoptions: {
sopt: ['eq','cn'],
dataUrl: //get data from server
buildSelect: function (data) {
var response, s = '<select>', i;
response = jQuery.parseJSON(data);
s += '<option value="0">--Select Book Title--</option>';
if (response && response.length) {
$.each(response, function (i) {
s += '<option value="' + this.Name+ '">' + this.Name+ '</option>';
});
}
return s + '</select>';
}
}
}

I don't need dropdown in toolbar input
My search operator dropdown list doesn't open.
The problem is only when my own jqgrid is loaded by ajax in to jquery dialog.
$( "#my_dialog" ).dialog({
width:'auto',
open: function(event, ui){
$.ajax(
{
url: "some.php",
type: "POST",
data: "is_dialog=true",
error: function(){
},
beforeSend: function(){
$("#loader").show();
},
complete: function(){
$("#loader").hide();
},
success: function( strData ){
$("#dialog_content").html(strData );
}
}
);
},
});
...........
<div id="my_dialog" >
<div id="dialog_content"></div>
</div>

Related

415 Unsupported Media Type Error

I'm getting an error of
"415 Unsupported media type". I've tried the solutions provided already.But my problem is not solved.
Here is my Code for receiving loading jason data dynamically in jqgrid
jQuery(grid_selector).jqGrid({
contentType: "application/json",
datatype: "json",
height: 250,
colNames:['Workbook Name','Superior','Hierarchy','Usage', 'Created', 'Created by'],
colModel:[
{name:'name',index:'name', width:90,editable: true,formatter:function(rowId, val, rawObject, cm, rdata) {
return "<a href='1.1.1 Edit Workbook (Name).html' style='height:25px;width:120px;' type='button' >"+rawObject.name+"</a>";
},unformat:undoaddLink,search: true},
{name:'recordType',index:'recordType', width:90,formatter:function(rowId, val, rawObject, cm, rdata) {
return "<a href='#' type='button' >"+rawObject.recordType+"</a>";
},editable: true,editoptions: { readonly: 'readonly' },unformat:undoaddLinkparent,search: true},
{name:'hierarchy',index:'hierarchy', width:150,editoptions: { readonly: 'readonly' },formatter: setVal,search: true,unformat:undohierarchy},
{name:'usage',index:'usage', width:90,editable: true,editoptions: { readonly: 'readonly' },search: true,formatter:ChangeVal},
{name:'created',index:'created', width:70,editable: true, editoptions: { readonly: 'readonly' },search: true},
{name:'createdBy',index:'createdBy', width:90,editable: true,editoptions: { readonly: 'readonly' },search: true}
],
viewrecords : true,
rowNum:10,
rowList:[10,20,30],
pager : pager_selector,
altRows: true,
'cellEdit': true,
'cellsubmit' : 'clientArray',
editurl: 'clientArray',
multiselect: true,
multiboxonly: true,
sortable: true,
gridComplete: function() {
$("tr").not(':first').hover(
function () {
$(this).css("background","#CCCCFF");
},
function () {
$(this).css("background","");
}
);
},
loadComplete : function() {
var table = this;
setTimeout(function(){
styleCheckbox(table);
updateActionIcons(table);
updatePagerIcons(table);
enableTooltips(table);
}, 0);
},
});
I'm getting the jason data currectly in localhost.But in server I'm getting the error.
Thanks in advance

Add check boxes in Jquery grid view

I have the following code in page which binds the data to j query grid.
Now i want to add one more column for check-boxes to the existing grid and when i select some check boxes and press some button .. i need to get the selected row values .
I have seen some tutorials for this they mentioned about some formatter .... but they are not clear
Please help me to achieve this.
Thanks in advance.
Code:
$(document).ready(function () {
$("#btn_GenerateEmpList").click(function () {
var firstClick = true;
if (!firstClick) {
$("#EmpTable").trigger("reloadGrid");
}
firstClick = false;
var empId= $("#txt_emp").val();
$.ajax({
type: "POST",
url: "PLBased.aspx/GetEmpNames",
data: JSON.stringify({ empId: empId}),
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (result) {
result = result.d;
jQuery("#EmpTable").jqGrid({
datatype: "local",
colNames: ['Emp Name'],
colModel: [
{ name: "EmpName", Index: "EmpName", width: 80 }
],
data: JSON.parse(result),
rowNum: 10,
rowList: [5, 10, 20],
pager: '#pager',
loadonce: false,
viewrecords: true,
sortorder: 'asc',
gridview: true,
autowidth: true,
sortname: 'EMPID',
height: 'auto',
altrows: true,
});
},
error: function (result) {
alert("There was some error ");
}
});
});
});
You can use customformatter to show checkbox in the column. For this, you can write the code as below in your jqGrid Code.
colNames: ['Id','Emp Name','Emp Checkbox'],
colModel: [
{ name: 'Id', index: 'Id', hidden: true },
{ name: 'EmpName', Index: 'EmpName', width: 80 },
{ name: 'Empchk', Index: 'Empchk', width: 50, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "true:false" },
formatter: generateEmpCheckBox, formatoptions: { disabled: false } }
],
formatter function code as below,
function generateEmpCheckBox(cellvalue, options, rowObject) {
var checkedStr = "";
if (cellvalue == true) {
checkedStr = " checked=checked ";
}
return '<input type="checkbox" onchange="UpdateEmpcheckbox(' + rowObject.Id + ',this)" value="' + cellvalue + '" ' + checkedStr + '/>';
}
function UpdateEmpcheckbox(selectedId, chkBox) {
if ($(chkBox).prop("checked")) {
//you can write an ajax here, to update the server
//when the checkbox is checked
}
else if (!($(chkBox).prop("checked"))) {
//you can write an ajax here to update the server
//when the checkbox is unchecked
}
return false;
}
Set the option multiselect:true which will add column of checkboxes. Then add
$('#EmpTable').jqGrid('getGridParam', 'selarrrow')
will return an array of selected id's.

jqgrid textbox value not getting update

Problem: unable to get updatable value of textbox in jqgrid.
It just retrieve old value.
example - default value of textbox field inside jqgrid is - "0"
now, if i update its value to "1" and inspect the field then its value does not get updated into HTML and not able to retrieve with jqgrid object through below syntax.
var rowData = $('#gerList').jqGrid('getRowData', rowId);
Below is my jqgrid stuff:
$('#gerList').jqGrid({
ajaxGridOptions: {
error: function () {
$('#gerList')[0].grid.hDiv.loading = false;
alert('An error has occurred.');
}
},
url: '#Url.Action("GetEnrolls", "Attendance")/' + 0,
gridview: true,
autoencode: true,
postData: { adID: rowID },
datatype: 'json',
jsonReader: { root: 'List', page: 'Page', total: 'TotalPages', records: 'TotalCount', repeatitems: false, id: 'syStudentID' },
mtype: 'GET',
colNames: ['GrdID', 'name', 'Minutes', 'comment'],
colModel: [
{ name: 'syID', index: 'syID', hidden: true },
{ name: 'FullName', index: 'FullName', width: 150 },
{
name: 'Min', index: 'Min', width: 75, align: 'left', formatter: function (cellValue, option) {
return '<input type="text" style="width: 40px" name="txtMin" id="txt_' + option.rowId + '" value="' + cellValue + '" />';
}
},
{ name: 'MSG', index: 'MSG', width: 150 }
],
pager: $('#gerListPager'),
sortname: 'syStudentID',
rowNum: 40,
rowList: [40, 80, 120],
width: '525',
height: '100%',
viewrecords: true,
beforeSelectRow: function (rowid, e) {
console.log("final");
var $txt = $(e.target).closest('tr').find('input[type="text"]');
alert($txt);
$txt.attr('value', rowid);
return true; // allow row selection*/
return true;
},
sortorder: 'desc'
}).navGrid('#gerListPager', { edit: false, add: false, del: false, search: false, refresh: false });
Please suggest me what is wrong to use this textbox in jqgrid.
In grid UI, all fields are non editable except textbox field appear to allow edit always.
Thanks
Try to use this:
jQuery("#gerList").saveRow("rowid", false, 'clientArray');

JqGrid Width resizing Issue with Browser resize

Can I set JqGrid width in a way that it automatically resizes with browser width.
Have tried using this.
autowidth:true,
.....
$(window).bind('resize', function () {
$("#table").setGridWidth($("#table").width());
}).trigger('resize');
Resizing isnt working as expected, When I resize the browser I expect grid to resize accordingly to that of browser width.
UPDATE:
$(function () {
$grid = $("#table");
$grid.jqGrid({
url: '../../Services/OrderService.asmx/getGlbOrders',
datatype: 'json',
mtype: 'POST',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
if (postData.searchField === undefined) postData.searchField = null;
if (postData.searchString === undefined) postData.searchString = null;
if (postData.searchOper === undefined) postData.searchOper = null;
//if (postData.filters === undefined) postData.filters = null;
return JSON.stringify(postData);
},
jsonReader: {
root: "d.rows",
page: "d.page",
total: "d.total",
records: "d.records",
id: "d.names"
},
colModel: [
{ name: 'select', label: 'select', width: 50,
formatter: function radio(cellValue, option) {
return '<input type="radio" name="radio_' + option.gid + '" value=' + cellValue + ' />';
}
},
{ name: 'code', label: 'Order ID' },
{ name: 'qty', label: 'Quantity' },
{ name: 'qtyr', label: 'Remaining Qty'},
{ name: 'uts', label: 'Units' },
{ name: 'status', label: 'Status' },
],
rowNum: 10,
rowList: [10, 20, 300],
sortname: 'name',
sortorder: "asc",
pager: "#pager",
viewrecords: true,
gridview: true,
rownumbers: true,
height: 250,
autowidth: true,
caption: 'Global Order List'
}).jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false });
})
$(window).bind('resize', function () {
$("#table").setGridWidth($("#table").width());
}).trigger('resize');
change your code from:
$(function () {
$grid = $("#table");
$grid.jqGrid({
// etc..
}).jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false });
})
$(window).bind('resize', function () {
$("#table").setGridWidth($("#table").width());
}).trigger('resize');
to:
$(function () {
$grid = $("#table");
$grid.jqGrid({
// etc..
}).jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false });
});
$(window).bind('resize', function () {
$("#table").setGridWidth($("#table").width());
}).trigger('resize');
You have forgotten a semicolon after the end of your jqGrid function. Then the code that comes after your function is ignored.

jqgrid apply filter after reload?

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

Resources