issue in showing pager after reloading the jqxgrid data on click event - jqxgrid

I am trying to reload the grid on click event. Here is my code for grid
var source = {
datatype: "json",
datafields: [
{ name: 'sno' },
{ name: 'bid' },
{ name: 'city' },
{ name: 'booking_date' },
{ name: 'amount' },
{ name: 'customer_contact' },
{ name: 'user_name' },
{ name: 'trip_type' },
{ name: 'comments' },
{ name: 'action' },
],
cache: false,
url: 'order_details.php?flag=2&start_date='+start_date_param+'&end_date='+end_date_param,
data: {
pagesize:50
},
root: 'Rows',
//sortcolumn: 'area',
// sortdirection: 'asc',
beforeprocessing: function (data) {
source.totalrecords = data[0].TotalRows;
}
};
dataadapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$("#jqxgrid").jqxGrid(
{
width: 1100,
source: dataadapter,
theme: 'classic',
autoheight: true,
pageable: true,
pagesize:50,
enablebrowserselection: true,
selectionmode: 'singlecell',
//sortable:true,
virtualmode: true,
rendergridrows: function (params) {
return params.data;
},
columns:
[
{ text: 'No', datafield: 'sno', width: 30 },
{ text: 'Booking Id', datafield: 'bid', width: 90, align: 'center',cellsAlign: 'center' },
{ text: 'City', datafield: 'city', width: 170 },
{ text: 'Car Book Date', datafield: 'booking_date', width: 100, align: 'center',cellsAlign: 'center' },
{ text: 'Amount', datafield: 'amount', width: 60, align: 'right',cellsAlign: 'right' },
{ text: 'Customer Contact', datafield: 'customer_contact', width: 205 },
{ text: 'User Name', datafield: 'user_name', width: 125 },
{ text: 'Trip Type', datafield: 'trip_type', width: 160},
{ text: 'Comments', datafield: 'comments', width: 80, align: 'center',cellsAlign: 'center'},
{ text: 'Action', datafield: 'action', width: 80, align: 'center',cellsAlign: 'center'},
]
});
// event handling on select of date range and click on button show
$("#btn_show").on("click", function (e) {
e.preventDefault();
var start_date_param = $("#start_date").val();
var end_date_param = $("#end_date").val();
source.url = 'order_details.php?flag=2&start_date='+start_date_param+'&end_date='+end_date_param;
dataadapter.dataBind();
});
On click of button "btn_show", I could get the data from page 0, but if I am on page 4, then after click event, my grid pager is remains on page 4 only and data is display for page 0.If I click on next page, then it jumps from page 0 to next page i.e page 5.
Why jqxgrid is not resetting its recordedstartindex and recordedendindex values on dataadapter.dataBind() call after click event?
Do I need to use any other function to reload my complete grid??

I think that the following:
$("#jqxgrid").jqxGrid('gotopage', 0);
should replace
dataadapter.dataBind();
In your code.

Related

how can i do to not lose a filter in a jqxGrid when a change the next page? i'm using the filters from my dataAdapter

i have a problem, i use this control is a jqxGrid, this is:
function initGridUsuarios() {
// campos y adaptador
var fields = [
{ name: "NoEmpleado", type: "int" },
{ name: "Nombre", type: "string" },
{ name: "Departamento", type: "string" }
],
dataAdapter = utils.generateGridAdapter(gridEmpleados, "GestionPaqueteInfo", "ObtenerGridUsuarios", fields, getGridFilters);
gridEmpleados.jqxGrid({
width: 900,
height: 400,
theme: tema,
columnsresize: true,
pageable: true,
altrows: true,
virtualmode: true,
rendergridrows: function () {
return dataAdapter.records;
},
localization: utils.getIdiomaGrid(),
source: dataAdapter,
columns: [
{ text: "Id", dataField: "Id", columngroup: "Titulo", width: 100, hidden: true },
{ text: "Número de Empleado", dataField: "NoEmpleado", columngroup: "Titulo", width: 150 },
{ text: "Nombre", dataField: "Nombre", columngroup: "Titulo", width: 250 },
{ text: "Departamento", dataField: "Departamento", columngroup: "Titulo", width: 350 },
{
text: "Crear paquete info", datafield: "Crear", columngroup: "Titulo", columntype: "button", width: 150, cellsrenderer: function () {
return "Crear";
}, buttonclick: function (clickRow) {
crear();
}
},
],
columngroups: [
{ text: "Busqueda de Empleados para creación de paquete inventario informática", align: "center", name: "Titulo" }
]
});
}
actually it loose the filter, when i change the page, what can i do to not lose the filter?
:$ sorry my english is not really good :$:$

get unformatted value of cell in jqgrid as parameter

I am trying to get the value of a cell to pass as a parameter in an ajax call for another column in the grid. The cell value I need is formatted to return a url so when I select it it is passing the url instead of the batchID value.
How can I access the value of BatchID without the formatter applied?
$(function () {
$('#search').html('');
$('#grid').GridUnload();
Grid.Home.Grid.setupGrid($('#grid'), $('#pager'), $('#search'));
});
Grid.Home.Grid = {
setupGrid: function (grid, pager, search) {
grid.jqGrid({
colNames: ['Batch ID', 'Job Start Date', 'Job Finish Date', 'Contacts', 'Statements', 'Selected', 'Sent', 'Queued', 'Action'],
colModel: [
{ name: 'BatchID', index: 'BatchID', width: 35, formatter: batch },
{ name: 'JobStartDate', index: 'JobStartDate', width: 55, sortable: false, search: false, formatoptions: { srcformat: 'y/m/dTH:i:s', newformat: 'm/d/Y g:i:s A'} },
{ name: 'JobFinishDate', index: 'JobFinishDate', width: 55, sortable: false, search: false, formatoptions: { srcformat: 'y/m/dTH:i:s', newformat: 'm/d/Y g:i:s A'} },
{ name: 'Contacts', index: 'Contacts', width: 20, align: 'right', sortable: false, search: false },
{ name: 'Statements', index: 'Statements', width: 20, align: 'right', sortable: false, search: false }, //'currencyFormatter' },
{name: 'Selected', index: 'Selected', width: 20, align: 'right', sortable: false, search: false },
{ name: 'Sent', index: 'Sent', width: 30, sortable: false, search: false, sortable: false, search: false },
{ name: 'Queued', index: 'Queued', width: 30, sortable: false, search: false },
{ name: 'Action', index: 'Action', width: 50, sortable: false, search: false, formatter: action}
],
loadonce: false,
pager: '#pager',
sortname: 'BatchID',
sortorder: "desc",
onCellSelect: function (rowid, cellcontent, e) {
if (cellcontent == '8') {
var rowObject = grid.getRowData(rowid);
if (rowObject.Action === 'Add To Queue'){
$.ajax({
type: 'POST',
url: '<%= Url.Action("UpdateBatch") %>',
data: { BatchID: rowObject.BatchID },
beforeSend: function (xhr) {
blockElement($('.grid'));
},
complete: function (xhr, status) {
unblockElement($('.grid'));
},
success: function (data) {
var title = $('<h6>', { html: data.Title, 'class': 'jgrowl-header' });
$.jGrowl(data.Message, {
theme: 'ui-state-highlight',
life: 5000,
beforeOpen: function (e, m, o) {
e.children('.header').html(title);
}
});
grid.trigger("reloadGrid");
}
}); }
};
},
url: '<%= Url.Action("GetBatchList") %>'
}).navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: true });
grid.filterToolbar({ stringResult: true, searchOnEnter: false });
}
};
function action(cellvalue, options, rowObject) {
if (rowObject.Action == 'Add To Queue'){
options.colModel.classes = 'show-link';
return 'Add To Queue'
}
else {
options.colModel.classes = '';
return '';
}
};
function batch(cellvalue, options, rowObject) {
var t = rowObject.BatchID;
return '' + t + ' ';
};
</script>
I used jsonmap and added another column that was hidden to hold the value of batchID unformatted. Now the grid looks like this.
Grid.Home.Grid = {
setupGrid: function (grid, pager, search) {
grid.jqGrid({
colNames: ['Batch', 'Job Start Date', 'Job Finish Date', 'Contacts', 'Statements', 'Selected', 'Sent', 'Queued', 'Action', ''],
colModel: [
{ name: 'BatchIDLink ', index: 'BatchID', jsonmap: 'BatchID', width: 35, formatter: link },
{ name: 'JobStartDate', index: 'JobStartDate', width: 55, sortable: false, search: false, formatoptions: { srcformat: 'y/m/dTH:i:s', newformat: 'm/d/Y g:i:s A'} },
{ name: 'JobFinishDate', index: 'JobFinishDate', width: 55, sortable: false, search: false, formatoptions: { srcformat: 'y/m/dTH:i:s', newformat: 'm/d/Y g:i:s A'} },
{ name: 'Contacts', index: 'Contacts', width: 20, align: 'right', sortable: false, search: false },
{ name: 'Statements', index: 'Statements', width: 20, align: 'right', sortable: false, search: false }, //'currencyFormatter' },
{name: 'Selected', index: 'Selected', width: 20, align: 'right', sortable: false, search: false },
{ name: 'Sent', index: 'Sent', width: 30, sortable: false, search: false, sortable: false, search: false },
{ name: 'Queued', index: 'Queued', width: 30, sortable: false, search: false },
{ name: 'Action', index: 'Action', width: 50, sortable: false, search: false, formatter: queue },
{ name: 'BatchIDVal', index: 'BatchID', jsonmap: 'BatchID', hidden: true }
],

JqGrid not loading in web page in asp.net mvc3

I am having an aspx engine view where the jqgrid must be loaded.
But the jqgrid is not loading. I tried with breakpoint using firebug but it has not hitted also
In the view
<asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
<table id="jqgprojectnew" style="width: 100%">
</table>
<script type="text/javascript">
var url = '<%#Url.Action("Listmanoj")%>';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
var colModel = [
{ name: 'Orderid', index: 'Orderid', align: 'left', width: 20 },
{ name: 'Customername', index: 'Customername', edittype: 'image', align: 'left', width: 70, },
{ name: 'Price', index: 'Price', align: 'left', width: 100, },
{ name: 'Quantity', index: 'Quantity', align: 'left', width: 150, },
{ name: 'Productname', index: 'Productname', align: 'left', width: 150 },
{ name: 'Totalincludingtax', index: 'Totalincludingtax', align: 'left', width: 150 },
{ name: 'Email', index: 'Email', align: 'left', width: 100, },
{ name: 'Town', index: 'Town', align: 'left', width: 100 },
{ name: 'Country', index: 'Country', align: 'left', width: 100, },
{ name: 'Postcode', index: 'Postcode', align: 'left', width: 70 },
{ name: 'Homephone', index: 'Homephone', align: 'left', width: 70 },
{ name: 'Workphone', index: 'Workphone', align: 'left', width: 70 },
{ name: 'Deliveryname', index: 'Deliveryname', align: 'left', width: 70 },
{ name: 'Deliverytown', index: 'Deliverytown', align: 'left', width: 70 },
{ name: 'Deliveryphone', index: 'Deliveryphone', align: 'left', width: 70 },
{ name: 'Deliverypostalcode', index: 'Deliverypostalcode', align: 'left', width: 70 },
{ name: 'Shippingmethod', index: 'Shippingmethod', align: 'left', width: 70 }
];
var sortname = 'Orderid';
var sortorder = 'desc';
SetGrid('#jqgprojectnew', '', url, colNames, colModel, sortname, sortorder, -1);
});
</script>
In the Web page view how it is loading
<script type="text/javascript"> $(document).ready(function () {
$("a.button").button();
var url = '';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
Code for setting grid:
function SetGrid(v_gridCtrl,v_pagingCtrl, v_url, v_colNames, v_colModel, v_sortname, v_sortorder, v_Pagesize) {
if (v_Pagesize == undefined)
v_Pagesize = 100;
$(v_gridCtrl).jqGrid({
//url from wich data should be requested
autowidth: true,
url: v_url,
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: v_colNames,
//columns model
colModel: v_colModel,
//pager for grid
pager: $(v_pagingCtrl),
//enable dynamic scrolling
//scroll: true,
//enable npage request parameter
prmNames: { npage: 'npage' },
//number of rows per page
rowNum: v_Pagesize,
rowList: [10, 30, 60, 90, 100, 150, -1],
loadComplete: function () {
$("option[value=-1]").text('All');
$('#count').html($(v_gridCtrl).getGridParam("reccount"));
},
//initial sorting column
sortname: v_sortname,
//initial sorting direction
sortorder: v_sortorder,
//we want to display total records count
viewrecords: true,
//grid height
height: 400,//'100%',
width: '100%',
scrollOffset: 0,
shrinkToFit: true
});
}
My problems are:
The action method which is used in the jqgrid is not hitind and on load the url action result is empty
Add document.ready() in script
Set url like this:
var url = '/ControllerName/Listmanoj'; //If your controller name is TestController, the url should be '/Test/Listmanoj'
Remove the following section:(why do you need that?)
$(document).ready(function () {
$("a.button").button();
var url = '';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
Include setGrid in document.ready().
In short, you script section should look like:
<asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
<table id="jqgprojectnew" style="width: 100%">
</table>
<script type="text/javascript">
$(document).ready(function()
{
//set grid function
function SetGrid(v_gridCtrl,v_pagingCtrl, v_url, v_colNames, v_colModel, v_sortname, v_sortorder, v_Pagesize) {
if (v_Pagesize == undefined)
v_Pagesize = 100;
$(v_gridCtrl).jqGrid({
//url from wich data should be requested
autowidth: true,
url: v_url,
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: v_colNames,
//columns model
colModel: v_colModel,
//pager for grid
pager: $(v_pagingCtrl),
//enable dynamic scrolling
//scroll: true,
//enable npage request parameter
prmNames: { npage: 'npage' },
//number of rows per page
rowNum: v_Pagesize,
rowList: [10, 30, 60, 90, 100, 150, -1],
loadComplete: function () {
$("option[value=-1]").text('All');
$('#count').html($(v_gridCtrl).getGridParam("reccount"));
},
//initial sorting column
sortname: v_sortname,
//initial sorting direction
sortorder: v_sortorder,
//we want to display total records count
viewrecords: true,
//grid height
height: 400,//'100%',
width: '100%',
scrollOffset: 0,
shrinkToFit: true
});
}// end of set grid function
var url = 'controllername/Listmanoj';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
var colModel = [
{ name: 'Orderid', index: 'Orderid', align: 'left', width: 20 },
{ name: 'Customername', index: 'Customername', edittype: 'image', align: 'left', width: 70, },
{ name: 'Price', index: 'Price', align: 'left', width: 100, },
{ name: 'Quantity', index: 'Quantity', align: 'left', width: 150, },
{ name: 'Productname', index: 'Productname', align: 'left', width: 150 },
{ name: 'Totalincludingtax', index: 'Totalincludingtax', align: 'left', width: 150 },
{ name: 'Email', index: 'Email', align: 'left', width: 100, },
{ name: 'Town', index: 'Town', align: 'left', width: 100 },
{ name: 'Country', index: 'Country', align: 'left', width: 100, },
{ name: 'Postcode', index: 'Postcode', align: 'left', width: 70 },
{ name: 'Homephone', index: 'Homephone', align: 'left', width: 70 },
{ name: 'Workphone', index: 'Workphone', align: 'left', width: 70 },
{ name: 'Deliveryname', index: 'Deliveryname', align: 'left', width: 70 },
{ name: 'Deliverytown', index: 'Deliverytown', align: 'left', width: 70 },
{ name: 'Deliveryphone', index: 'Deliveryphone', align: 'left', width: 70 },
{ name: 'Deliverypostalcode', index: 'Deliverypostalcode', align: 'left', width: 70 },
{ name: 'Shippingmethod', index: 'Shippingmethod', align: 'left', width: 70 }
];
var sortname = 'Orderid';
var sortorder = 'desc';
SetGrid('#jqgprojectnew', '', url, colNames, colModel, sortname, sortorder, -1);
});
</script>

Displaying a Blank JQGrid with Column Headers

I want to display JQGrid with all column headers but without any data rows when the page loads.
Based upon user selection through autocomplete i want to populate the JqGrid with data.
The problem is that each time during pageload the grid is automatically populated.
How can i get around this ?
This is how i am using the grid with VS2008 MVC2
jQuery('#jgrid').jqGrid({
autowidth: true,
altRows: true,
altclass: 'grdAltRwClr',
datatype: 'xml',
forceFit: true,
gridview: true,
height: 290,
mtype: 'post',
rowList: [10, 20, 30],
rowNum: 10,
pager: '#pager',
pagerpos: 'right',
recordpos: 'left',
rownumbers: false,
scrollrows: false,
sortname: 'roledtlid',
toolbar: [true, "top"],
url: rootPath + 'RoleDetail/JGridData',
beforeSelectRow: function(rowid, e) { return false; },
gridComplete: function() { GridComplete() },
colModel: [
{ name: 'act', label: 'View', resizable: false, search: false, sortable: false, title: false, width: 6, index: 'act' }
, { name: 'roledtlid', label: 'R.Detail id', width: 15, index: 'roledtlid' }
, { name: 'roleid', label: 'Role id', width: 10, index: 'roleid' }
, { name: 'rolename', label: 'Role Name', width: 25, index: 'rolename' }
, { name: 'pageid', label: 'Page ID', width: 10, index: 'pageid' }
, { name: 'pgname', label: 'Page Name', width: 30, index: 'pgname' }
, { name: 'canadd', label: 'Add', width: 10, index: 'canadd' }
, { name: 'canedit', label: 'Edit', width: 10, index: 'canedit' }
, { name: 'candel', label: 'Delete', width: 10, index: 'candel' }
, { name: 'canview', label: 'View', width: 10, index: 'canview' }
]
});
Thanks
Don't provide a url. Instead set your datatype to "local" and use code similar to the following:
var mySearchData = // Get your search data...
$.post('#Url.Action("Getars")', mySearchData, function(gridData) {
var rowIds = $('#carGrid').jqGrid('getDataIDs');
for (var i = 0, len = rowIds.length; i < len; i++) {
var currRow = rowIds[i];
$('#carGrid').jqGrid('delRowData', currRow);
}
$('#carGrid').jqGrid('setGridParam', { data: gridData }).trigger('reloadGrid');
}).error(function (jqXHR, textStatus) {
app.showErrorAlert(jqXHR.responseText);
});
}

jqGrid the correct way to expand column width

I am attempting to widen my columns here with the colModel property of jqGrid. when I do this, my table data disappears. Does any body know why this would happen. Before and after pictures will be below. As well as the jquery code that I use.
Here is an example of it working.
Here is an example after I have attempted to widen the columns
jQuery(document).ready(function () {
ShowMessage();
tableToGrid("#table1", {
height: '200',
shrinkToFit: false,
autowidth: true,
colNames: ['Edit',
'MRN',
'Hospital Fin',
'First Name',
'Last Name',
'Date of birth',
'Completed Pathway',
'Completed Pathway Reason',
'PCP Appointment',
'Specialist Appointment',
'Admit Date',
'Discharge Date',
'Discharge Disposition',
'Discharge To',
'Discharge Advocate Call',
'Home Healthcare',
'Safe Landing Accepted',
'PCP Name',
'PCP Phone',
'PCP Appointment Location',
'Specialist Name',
'Specialist Phone',
'Specialist Appointment Location',
'Comments',
'Patient Room',
'Phone',
'Payor',
'MRN Type'
],
colModel: [{ name: 'Edit', width: 55 },
{ name: 'MRN', width: 55 },
{ name: 'HospitalFin', width: 85 },
{ name: 'FirstName', width: 85 },
{ name: 'LastName', width: 85 },
{ name: 'Dateofbirth', width: 85 },
{ name: 'CompletedPathway', width: 145 },
{ name: 'CompletedPathwayReason', width: 165 },
{ name: 'PCPAppointment', width: 145 },
{ name: 'SpecialistAppointment', width: 165 },
{ name: 'AdmitDate', width: 55 },
{ name: 'DischargeDate', width: 80 },
{ name: 'DischargeDisposition', width: 180 },
{ name: 'DischargeTo', width: 55 },
{ name: 'DischargeAdvocateCall', width: 165 },
{ name: 'HomeHealthCareAccepted', width: 165 },
{ name: 'SafeLandingAccepted', width: 165 },
{ name: 'PCPName', width: 55 },
{ name: 'PCPPhone', width: 55 },
{ name: 'PCPAppointmentLocation', width: 165 },
{ name: 'SpecialistName', width: 185 },
{ name: 'SpecialistPhone', width: 185 },
{ name: 'SpecialistAppointmentLocation', width: 185 },
{ name: 'Comments', width: 55 },
{ name: 'PatientRoom', width: 85 },
{ name: 'Phone', width: 85 },
{ name: 'Payor', width: 85 },
{ name: 'MRNType', width: 85 }
]
});
$(window).bind('resize', function () {
$("#table1").fluidGrid({ example: "#tempplateInfo", offset: -10 });
$("#table1 tbody").sortable("destroy");
});
(function ($) {
jQuery.jgrid.fluid = {
fluidGrid: function (options) {
var grid = $(this);
var settings = $.extend({
example: grid.closest('.ui-jqgrid').parent(), offset: 0
},
options || {});
var width = $(settings.example).innerWidth() + settings.offset; grid.setGridWidth(width);
}
}
})
(jQuery);
jQuery.fn.extend({ fluidGrid: jQuery.jgrid.fluid.fluidGrid });
var $grid = $('#table1'),
hdiv = $grid[0].grid.hDiv,
$columnHeaders = $("thead tr.ui-jqgrid-labels th", hdiv)
$columnHeaders.unbind('mouseenter');
$columnHeaders.unbind('mouseleave');
Comment out the columnModel section to get an idea of what I had when it was working. Should the colModel name property be equal to the th for instance? What is the word good fellows. I am getting inconsitent results.

Resources