Options for selecting multiple rows and individual rows - asp.net-mvc-3

I am using JQGrid and I want an option for multiple selection of rows. I used " multiselect: true," but it is not working. Yes I have got an column in the grid that have checkbox in each row but if I select top checkbox which is in header , it just selects first row from grid
Even single selection of row is not working properly. If checked at one checkbox, it selects and then if I check another box in the another row, it unchecks the first checked checkbox.
Here is my grid Code.
$(document).ready(function () {
$("#btnGetdetails").click(function () {
bindReports();
});
var bindReports = function () {
$('#list1').jqGrid('GridUnload');
$("#list1").jqGrid({
url: "GetNotesReportDetails",
postData: { startDate: $('#startDate').val(), endDate: $('#endDate').val(), ins_Type: $("#InsuranceType").val(), ass_Clincian: $("#ddlAssignedClician").val() },
datatype: "json",
mtype: "POST",
colNames: ["ID", "#", "First Name", "Last Name", "Date Of Birth", "Date of Visit", "Insurance Type", "Insurance ID","Clinician" ,"Procedure Code", "Fee Schedule"],
colModel: [
{ name: "ID", index: "ID", hidden: true, key: true },
{ name: "SNo", index: "SNo", width: 10, align: "left" },
{ name: "FirstName", index: "FirstName", width: 40, align: "left", sortable: true, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Link('", addParam: "');" } },
{ name: "LastName", index: "LastName", width: 40, align: "left", sortable: true, formatter: 'showlink', formatoptions: { baseLinkUrl: 'javascript:', showAction: "Link('", addParam: "');" } },
{ name: "DateofBirth", index: "DateofBirth", width: 40, align: "left", formatter: 'date', sorttype: "date", sortable: true },
{ name: "DateofVisit", index: "DateofVisit", width: 40, align: "left", formatter: 'date', sorttype: "date", sortable: true },
{ name: "PageType", index: "PageType", width: 40, align: "left", sortable: true },
{ name: "InsuranceID", index: "InsuranceID", width: 50, align: "left", sortable: true },
{ name: "Clinician", index: "Clinician", width: 50, align: "left", sortable: true },
{ name: "ProcedureCode", index: "ProcedureCode", width: 50, align: "left", sortable: true },
{ name: "CodeFee", index: "CodeFee", width: 50, align: "left", sortable: true }],
// Grid total width and height
multiselect: true,
rowNum: 20,
rowList: [5, 10, 15, 20],
width: 900,
height: "100%",
// Paging
pager: $("#pager1"),
viewrecords: true,
// Default sorting
//sortname: "FirstName",
sortorder: "asc",
sortable: true,
loadonce: true,
hidegrid: false,
// Grid caption
caption: "Reports List"
}).navGrid("#pager1", { refresh: false, excel: true, add: false, edit: false, del: false }, {}, // settings for edit
{}, // settings for add
{}, // settings for delete
{ sopt: ["cn"] } // Search options. Some options can be set on column level
).jqGrid('navButtonAdd', '#pager1', {
caption: "Export to Excel",
buttonicon: "ui-icon-bookmark",
onClickButton: genGraph,
position: "last"
});
}
});

Probably you have problem in your data. You used key: true for the column ID. It means that jqGrid will assign the value of id attribute of every row (id of <tr> element) with the value from ID column. If you would have the same values in ID column instead of providing unique values you would have exact the same behavior like you described in your question. If jqGrid will need to select or unselect an row then it will search the row by id. It will find the first row with the id if one have more as one row with the id. So it will select/unselect the first row in the grid in many cases.

Related

How to make JqGrid always have empty row at bottom?

I'm using JqGrid with inline editing and i dont use navigation, pager or footer. I want to add empty row at the bottom to added. I mean empty row will be always there after editing an exsiting row, after adding new row.
I added row in loadComplete event, but i just adds empty row at beginning not anymore.
jQuery("#tableContents").jqGrid({
postData: { orderId: '139358' },
mtype: "POST",
url: "test.asmx/GetContents",
datatype: "json",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: { repeatitems: true, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
colNames: ['Master Content ID', 'Description Of Goods', 'No Of Items', 'Total Value for Customs', 'Weight', 'Track No'],
colModel: [
{
name: 'master_content_id', index: 'master_content_id', width: 60, hidden: true, editable: true, editrules: { edithidden: false }
},
{
name: 'content', index: 'content', width: 60, sorttype: "string", editable: true, edittype: "text",
editrules: {
required: true
}
},
{
name: 'piecesInt', index: 'piecesInt', width: 90, align: "right", sorttype: "int", editable: true,
editrules: {
number: true,
required: true
}
},
{
name: 'value', index: 'value', width: 100, align: "right", sorttype: "float", editable: true,
editrules: {
required: true
}
},
{
name: 'weight', index: 'weight', width: 80, align: "right", sorttype: "float", editable: true,
editrules: {
required: true
}
},
{
name: 'track_no', index: 'track_no', width: 80, align: "right", sorttype: "string", editable: true
},
],
rowNum: 10,
rowList: [10, 20, 30],
//pager: jQuery('#pager1'),
sortorder: "desc",
viewrecords: true,
regional: 'tr',
height : '100%',
caption: "Manipulating Array Data",
editurl: 'test.asmx/EditContent',
loadonce: true,
sortable: true,
//footerrow: true,
onSelectRow: function (rowid) {
var $self = $(this),
// savedRows array is not empty if some row is in inline editing mode
savedRows = $self.jqGrid("getGridParam", "savedRow");
if (savedRows.length > 0) {
$self.jqGrid("restoreRow", savedRows[0].id);
}
$self.jqGrid("editRow", rowid, {
keys: true,
extraparam: { orderId: '139358', staffId : '111' },
aftersavefunc: function (rowid) {
alert("Saved");
}
});
},
loadComplete: function () {
var $self = $(this)
$self.jqGrid('addRowData', undefined, {});
}
});
How can we do that?
You try to use jqGrid in the way which is opposite to the standard behavior. It's very bad idea. You will have to write a lot of code and have minimal difference to the standard way.
The main problem is: jqGrid hold data inside of the grid. You try to add an empty row inside of the data which is not loaded from the server, which is not in editing mode (like addRow do for example) and which is not saved on the server. So you try to use the grid in the way contradicting to jqGrid logic. It sounds simple, but it is really bad and the implementation will be complex.
I would recommend you to follow the standard way. You will have clean and simple code and the most of the users can use the grid intuitive. For example you can do add navigator toolbar where you add "+"/"Add" button with respect of inlineNav. The user will intuitively understand what need be done to add new row. The difference whether the user clicks on empty row at the bottom of the grid or if the user clicks on "Add new row" button, existing also at the bottom of the grid, is very small. After the click on the button the new row will be added and the user can insert the data. By press of Enter the row will be saved and by press on Esc the empty row will be removed. The code will be simple and it will do almost the same what you try to implement now.

Jquery Grid row remains in the edited form saveRow event is called and another row is clicked

I have a grid that is loaded inside a jquery dialog. I have done row editing and row saving within onSelectRow event. When a row is edited and saved and then another row is clicked, previous row remains in the edited form. I am not able to save and remove the edited form.
Id of my table on which I want to load the grid is MultiCount.
And I have binded the grid inside a function bindShapesGrid(), below is the code.
I have hardcoded a XML String and used it as the data.
function bindShapesgrid() {
var xmlstring = "<root><rows><row><cell>Shortnamevalue</cell><cell>does not equal</cell><cell>and</cell><cell>sad</cell><cell></cell><cell></cell></row><row><cell></cell><cell></cell><cell></cell><cell></cell><cell></cell><cell></cell></row></rows></root>"
var lastsel2;
jQuery("#MultiCount").jqGrid({
datatype: 'xmlstring',
datastr: xmlstring,
colNames: ['ShortName', 'Operand 1', 'Value 1', 'AndOr', 'Operand 2', 'Value 2'],
colModel: [{ name: 'ShortName', index: 'ShortName', align: 'center', width: 80, editable: true, edittype: "select" },
{ name: 'Operand1', index: 'Operand1', align: 'center', width: 90, editable: true, edittype: "select", editoptions: { value: RetrievegridOperandList() } },
{ name: 'Value1', index: 'Value1', align: 'center', width: 40, editable: true },
{ name: 'AndOr', index: 'Refer', align: 'center', width: 80, editable: true, edittype: "select", editoptions: { value: "AND:And;OR:Or" } },
{ name: 'Operand2', index: 'Operand2', align: 'center', width: 80, edittype: "select", editable: true, editoptions: { value: RetrievegridOperandList() } },
{ name: 'Value2', index: 'Value2', align: 'center', width: 40, editable: true }],
root: 'rows',
row: 'row',
celledit: true,
sortname: 'ShortName',
sortorder: 'asc',
viewrecords: true,
gridview: true,
height: "100%",
rowNum: 10,
onSelectRow: function (id) {
if (id && id !== lastsel2) {
jQuery('#MultiCount').jqGrid('editRow', id, true);
jQuery("#MultiCount").jqGrid('saveRow', lastsel2, true);
lastsel2 = id;
}
}
});
}

jqGrid - sort not working

$("#grid").jqGrid({
datatype: 'local',
mtype: 'GET',
loadui: 'block',
altRows: true,
altclass: "myAltRow",
multiselect: false,
recordpos: "right",
pagerpos: "center",
pager: $('#gridt_summarypager'),
pginput: false,
rowNum: 100,
recordtext: "Showing {0} - {1} of {2}",
viewrecords: true,
sortname: 'Project',
sortorder: 'asc',
colNames: ['ProjectID', '<%: Project %>', '<%: ProjectTitle %>' , 'ProjectItemID', '<%: usProjectItem %>', 'Hours To Authorise', 'Hours Not Posted', 'Hours Rejected', 'Last 12 Months'],
colModel: [
{ name: 'ProjectID', index: 'ProjectID', width: 0, hidden: true},
{ name: 'Project', index: 'Project', width: 90, align: 'left', formatter: htmlEncodedString },
{ name: 'ProjectTitle', index: 'ProjectTitle', width: 90, align: 'left', formatter: htmlEncodedString },
{ name: 'ProjectItemID', index: 'ProjectItemID', width: 0, hidden:true },
{ name: 'ProjectItem', index: 'ProjectItem', width: 100, align: 'left', formatter: htmlEncodedString },
{ name: 'HoursToAuthorise', index: 'HoursToAuthorise', width: 125, align: 'right', formatter: timesheetsProjectToAuthoriseQueryFormat },
{ name: 'HoursNotPosted', index: 'HoursNotPosted', width: 125, align: 'right', formatter: timesheetsProjectUnpostedQueryFormat<% if (!(bool)ViewData["PostingEnabled"]) { %>, hidden: true <% } %> },
{ name: 'HoursRejected', index: 'HoursRejected', width: 125, align: 'right', formatter: timesheetsProjectRejectedQueryFormat },
{ name: 'HoursSubmitted12Months', index: 'HoursSubmitted12Months', width: 125, align: 'right', formatter: timesheetsProjectYearQueryFormat }],
imgpath: '../../Scripts/css/ui-lightness/images',
height: 145,
shrinkToFit: false,
hoverrows: false,
loadError: function (xhr, st, err) {
if (xhr.status == 200) {
window.location = '<%= loginPage %>';
}
else if (xhr.status == 500) {
$('#grid_summary_errors').html(xhr.statusText);
}
},
beforeSelectRow: function(rowid, e) {
/* disable row selection */
return false;
},
onSortCol: function (index, columnIndex, sortOrder) {
var col = $("#grid_summarygrid").getGridParam('colNames');
var label = "Ordered by " + col[columnIndex] + " " + sortOrder + "ending";
$("#gridsort").text(label);
}
});
$("#grid").setGridParam({ url: '<%= Url.Action(dataMethod, controllerName)%>?qid=xxx', page: 1, datatype: "json" })
.trigger('reloadGrid');
Currently using jqGrid 4.4.1 and it loads data fine but once sort is applied it updates the sort label buy grid data is not sorted. What is going on? Any help most appreciated...
If you set url and change datatype of grid to "json" then your server code is responsible for sorting of data like for paging too. If you want to load all data for the grid at once and want that jqGrid do sorting and paging for you then you should use loadonce: true option.
I recommend you additionally to include gridview: true option in jqGrid, replace pager: $('#gridt_summarypager') to pager: '#gridt_summarypager', remove not existing parameter imgpath and consider to use autoencode: true option of jqGrid which makes HTML encoding of strings in all columns which not contains custom formatter.
{
name: "name",
index:"name",
**sortable: true,**
editable: true,
**sorttype: 'text',**
key: true
},
Make sure that sorttype complies with the fields data type. for example if the grid field "name" contains int numbers, then you should have sorttype: 'int'.
Also as mentioned by Oleg, you need to set loadonce to true.
pager: "#pager",
gridview: true,
rowNum: 5,
loadonce:true,
multiSort: true,
rownumbers: true,
viewrecords: true,
rowList: [5, 10, 15],
include sortable: true in column as well as jqgrid property.
Chaning this parameter value worked for me.
loadonce: true

JqGrid Custom search reload grid

Morning,
I am using jqGrid 4.4.1 - jQuery Grid. I have the next problem.
I have a custom search button, it permits filter data with some params
$('#BtnConsultar').click(function() {
parametros.NoSolicitud = $("#TxtNoSolicitud").val();
parametros.TipoSolicitud = $("#CbTiposSolicitud").val();
parametros.IdUsuario = $("#TxtIdUsuario").val();
parametros.Proveedor = $("#TxtProveedor").val();
parametros.FechaUltModificacionDesde = $("#TxtFechaUltModificacionDesde").val();
parametros.FechaUltModificacionHasta = $("#TxtFechaUltModificacionHasta").val();
parametros.FechaBorradoDesde = $("#TxtFechaBorradoDesde").val();
parametros.FechaBorradoHasta = $("#TxtFechaBorradoHasta").val();
jQuery('grid').jqGrid('clearGridData');
$("#GrdResultadoConsulta").jqGrid('setGridParam', { postData: { parametroJSON: JSON.stringify(parametros)} });
$('#GrdResultadoConsulta').trigger("reloadGrid", [{ current: true}]);
return true;
});
But if before filter data, i have a grid with 20 rows in group of 10 (2 pages) and the data that i want filter be in the second page the grid doesn´t show. I think is a sort problem because if i press colum sort the grid show the row.
Any one with some solution ?
This is my grid code
$("#GrdResultadoConsulta").jqGrid({
url: '<%= Url.Action("GridConsultaSolicitudeEliminadas")%>',
postData: { parametroJSON: JSON.stringify(parametros) },
datatype: 'json',
mtype: 'GET',
colNames: ['No.Solicitud', 'Tipo Solicitud', 'Usuario', 'Proveedor', 'Fecha Creación', 'Fecha Modificación', 'Fecha Borrado', 'Id Notificacion', 'SolicitudesEliminadasID'],
colModel: [
{ name: 'SolicitudID', index: 'SolicitudID', width: 75, align: 'left', sortable: true, resizable: false },
{ name: 'DescTipoSolicitud', index: 'TipoSolicitud', width: 75, align: 'center', sortable: true, resizable: false },
{ name: 'Usuario', index: 'IdUsuario', width: 200, align: 'left', sortable: true, resizable: false },
{ name: 'Proveedor', index: 'NumProv', width: 200, align: 'left', sortable: true, resizable: false },
{ name: 'FechaInicio', index: 'FechaInicio', width: 75, align: 'right', sortable: true, resizable: false },
{ name: 'FechaModificacion', index: 'FechaModificacion', width: 75, align: 'right', sortable: true, resizable: false },
{ name: 'FechaBorrado', index: 'FechaBorrado', width: 75, align: 'right', sortable: true, resizable: false },
{ name: 'IdNotificacion', width: 75, align: 'right', sortable: false, resizable: false },
{ name: 'SolicitudesEliminadasID', hidden: true }
],
pager: $('#GrdResultadoConsultaPager'),
rowNum: 10,
sortname: 'SolicitudID',
sortorder: 'asc',
autowidth: true,
height: '250px',
viewrecords: true,
caption: 'Resultado de consulta solicitudes eliminadas',
loadtext: "Cargando información ...",
hidegrid: false,
loadComplete: function() { },
onSelectRow: function(id) { }
}).navGrid('#GrdResultadoConsultaPager', { edit: false, add: false, search: false, del: false });
Thanks..
PD: Excuse for me english
I found my error.
The error wasn't in the grid, was in the stored procedure.
Solution: Moving the filters to CTE instruction and not in the final query result.
Regards

jqGrid formatCell event doesn't fire

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.

Resources