I want to apply background color to row of jqGrid row based on value of column, however the basic rowattr is not applying class to rows.
Below is the code (for simplicity I have removed the condition on which color needs to be applied)
jQuery("#employeeSalarysGrid").jqGrid({
height: 250,
url: 'http://localhost:50570/api/Test/Get',
mtype: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; },
id: "0",
cell: "",
repeatitems: false
},
datatype: "json",
colNames: ['Id', 'Bank Name', 'Bank Name', 'Employee name', 'Joining date', 'Salary amount', 'Comments'],
colModel: [
{ name: 'Id', align: "center", hidden: true },
{ name: 'BankName', index: 'BankName', align: 'center', editable: false },
{
name: 'BankId', index: 'BankId', align: "center", hidden: true, required: true,
viewable: true, editrules: { edithidden: true, required: true },
editable: true,
edittype: 'select',
editoptions: {
dataUrl: '/api/Test/GetBanks',
buildSelect: function (data) {
var response = jQuery.parseJSON(data);
var s = '<select>';
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
var bank = response[i];
s += "<option value=" + bank.BankId + ">" + bank.Name + "</option>";
}
}
return s + "</select>";
}
}
},
{ name: 'EmployeeName', align: "center", editable: true, editrules: { required: true } },
{ name: 'JoiningDate', align: "center", editable: true, editrules: { custom: true, custom_func: datecheck },
formatter: 'date', formatoptions: { srcformat: 'y-m-d', newformat: 'd-M-y' }, edittype: 'text', editable: true,
editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker({ dateFormat: 'd-M-y' }); }, 200); } }
},
//{ name: 'cdate', index: 'cdate', width: 80, align: 'right', formatter: 'date', srcformat: 'yyyy-mm-dd', newformat: 'm-d-Y', edittype: 'text', editable: true, editoptions: { dataInit: function (el) { setTimeout(function () { $(el).datepicker(); }, 200); } } },
{ name: 'SalaryAmount', align: "center", editable: true, editrules: { required: true } },
{ name: 'Comments ', align: "center", editable: true }
],
gridview: true,
autoencode: true,
ignorecase: true,
loadonce: true,
sortname: "InstallmentDate",
sortorder: "asc",
viewrecords: true,
rowNum: 10,
rowList: [10, 15, 20],
pager: '#employeeSalarysPager',
caption: "Employee Salary list",
rowattr: function (rd) {
return { "class": "rowClass" };
//alert("hi");
}
});
CSS style :
<style type="text/css">
.rowClass { color: blue; background-image: none;}
</style>
Note: If I uncomment //alert statement, it shows alert message 5 times. It means rowattr is getting invoked for each row, however css class is not getting applied.
Regards,
Abhilash
The rowattr do works correctly, but if you want that the class will be applied on selected rows too then you should change CSS rule to the following
.ui-widget-content .rowClass { color: blue; background-image: none; }
see the demo.
Related
I have a button and a grid (using jqGrid) but wanted to disable the button that is off the grid when the user clicks the checkbox that is within the grid. How do I do?
I'm trying to do this in LoadComplete.
<table id="Grid"></table>
<div id="GridPager"></div>
<br />
<button id="btnDownload" disabled="disabled">Download Selected</button>
<iframe id="ifr" style="display: none"></iframe>
<script>
$(document).ready(function () {
// make jQuery UI button
$("#btnDownload").button();
$("#btnDownload").click(function () {
var selectedIDs = jQuery('#Grid').jqGrid('getGridParam', 'selarrrow');
$("#ifr").attr("src", "/Handler/ExportInvoiceHandler.ashx?selectedIDs=" + selectedIDs);
});
$("#Grid").jqGrid({
url: '/Handler/InvoiceHandler.ashx',
datatype: 'json',
autowidth: true,
height: "100%",
emptyRecords: "No records found",
colNames: ['PO', 'SKU', 'Status', 'Date', ''],
colModel: [
{ name: 'PO', width: 80, sortable: true, stype: 'string', resizable: false },
{ name: 'SKU', width: 200, sortable: true, stype: 'string', resizable: false },
{ name: 'Status', width: 100, sortable: true, stype: 'string', resizable: false },
{
name: 'Date', width: 80, sorttype: "date", sortable: true, align: 'center', resizable: false,
searchoptions: {
dataInit: function (element) {
$(element).datepicker({ dateFormat: 'mm/dd/yy' })
}
}
},
{ name: 'Id', width: 50, sortable: false, search: false, index: 'Id', editable: true, formatter: returnHyperLink, align: 'center', resizable: false },
],
loadComplete: function () {
$("input[type=checkbox]").click(function () {
var chkSelected = $("#Grid input[type='checkbox']:checked").length;
var btn = $("#btnDownload");
alert(btn);
if (chkSelected != 0) {
btn.removeAttr('disabled');
}
else {
btn.attr('disabled', 'disabled');
}
});
},
rowNum: 10,
rowList: [10, 20, 30],
pager: '#GridPager',
multiselect: true,
sortname: 'PO',
viewrecords: true,
sortorder: 'asc',
loadonce: true
}).navGrid('#GridPager', { add: false, edit: false, del: false, refresh: false, search: true, refresh: true }, {}, {}, {}, { multipleSearch: true }, { closeOnEscape: true });
});
function returnHyperLink(cellValue, options, rowdata, action) {
return "<a href='/Handler/ExportInvoiceHandler.ashx?Id=" + options.rowId + "' target='ifr'>Download</a>";
}
</script>
I have a grid with very small columns with row filter, which cause them to have very small text-box. so I used
field: "OrderID",
width: 100,
filterable: {
cell: {
inputWidth: 65
}
}
but when I define inputWidth to enlarge the text field the filter operator does not move over and in fact cover up the partial space of the text-box. Therefore, I was wondering if there is a way to move the filter operator over or preferably over to the title header, like the columnMenu filter icon. Any help would be greatly appreciated, thanks.
I took the following example from: http://demos.telerik.com/kendo-ui/grid/filter-row
and modified width and inputwidth of orderID
<div id="example">
<div id="grid"></div>
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read:"http://demos.telerik.com/kendo- ui/service/Northwind.svc/Orders"
},
schema: {
model: {
fields: {
OrderID: { type: "number" },
Freight: { type: "number" },
ShipName: { type: "string" },
OrderDate: { type: "date" },
ShipCity: { type: "string" }
}
}
},
pageSize: 20,
serverPaging: true,
serverFiltering: true,
},
height: 550,
filterable: {
mode: "row"
},
pageable: true,
columns:
[{
field: "OrderID",
width: 100,
filterable: {
cell: {
inputWidth: 65
}
}
},
{
field: "ShipName",
width: 500,
title: "Ship Name",
filterable: {
cell: {
operator: "contains"
}
}
},{
field: "Freight",
width: 255,
filterable: {
cell: {
operator: "gte"
}
}
},{
field: "OrderDate",
title: "Order Date",
format: "{0:MM/dd/yyyy}"
}]
});
});
Here is the output I require!
Here is how I try to achieve this:
win = Ext.create('Ext.window.Window', {
height: 650,
width: 500,
layout: 'fit',
border: false,
bodyPadding: 10,
modal:true,
itemId:'serviceCallWindow',
header: {
cls: 'n-service-call-window-header',
height: 80,
items:[{
xtype: 'component',
floating: true,
autoShow: true,
shadow: false,
focusOnToFront:false,
defaultAlign: 't',
autoEl: {
tag: 'img',
src: NG.serverMapPath('~/resources/images/support/support_icon.png')
},
componentCls: 'n-service-call-support-icon'
}]
},
items: [{
xtype: 'servicecall',
border: false,
bodyPadding: 10
}]
});
The challenge is to get the service call icon between the window header and body.
How can I achieve this?
This is achievable through manipulating CSS and the various layouts. You would perhaps also need to get rid of the header and actually make your own "close" button which would fire the windows close method.
such as below:
Ext.application({
name: 'Fiddle',
launch: function() {
win = Ext.create('Ext.window.Window', {
height: 300,
width: 500,
border: false,
bodyPadding: 10,
header: false,
modal: true,
layout: 'vbox',
itemId: 'serviceCallWindow',
items: [{
xtype: 'container',
/*layout: {
type: 'hbox',
pack: 'center'
},*/
width: '100%',
items: [{
xtype: 'image',
cls: 'testLogo',
style: {
margin: '0 auto',
width: '50px',
display: 'block'
},
src: 'http://placehold.it/50x50'
}, {
xtype: 'button',
cls: 'testClose',
style: {
top: 0,
right: 0,
position: 'absolute'
},
icon: 'http://placehold.it/20x20',
listeners: {
click: function() {
win.close();
}
}
}],
}, {
xtype: 'container',
border: false,
bodyPadding: 10,
html: 'this is the content of another container'
}]
});
win.show();
}
});
Demo: https://fiddle.sencha.com/#fiddle/g6t
hii Guys!!!!.
In MyJqgrid Background color of Selected Row is not changing to 'yellow' whereas while Hovering It is changing.I want to change the color to yellow on slection.
<script type="text/javascript">
$(function () {
$("#UsersGrid").jqGrid({
url: 'getGriddahico.ashx',
datatype: 'json',
height: 250,
colNames: ['id', 'username', 'ordinal', 'authcode', 'extension', 'trunk', 'dialnumber', 'dialdate', 'dialtime', 'duration', 'destination', 'price', 'toc'],
colModel: [
{ name: 'id', index: 'id', width: 100, sortable: true, align: 'center' },
{ name: 'username', width: 100, sortable: true, align: 'center' },
{ name: 'ordinal', width: 100, sortable: true, align: 'center' },
{ name: 'authcode', width: 100, sortable: true, align: 'center' },
{ name: 'extension', width: 100, sortable: true, align: 'center' },
{ name: 'trunk', width: 100, sortable: true, align: 'center' },
{ name: 'dialnumber', width: 100, sortable: true, align: 'center' },
{ name: 'dialdate', width: 100, sortable: true, align: 'center' },
{ name: 'dialtime', width: 100, sortable: true, align: 'center' },
{ name: 'duration', width: 100, sortable: true, align: 'center' },
{ name: 'destination', width: 100, sortable: true, align: 'center' },
{ name: 'price', width: 100, sortable: true, align: 'center' },
{ name: 'toc', width: 150, sortable: true, align: 'center' }
],
rowNum: 100,
rowList: [100, 200, 300],
pager: '#UsersGridPager',
sortname: 'username',
viewrecords: true,
ignorecase:true,
sortorder: 'asc',
autowidth: true,
toppager: true,
height: '100%'
});
$("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false, search: false });
jQuery("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });
});
</script>
use css
.ui-jqgrid-btable .ui-state-highlight { background: yellow; }
or
.ui-jqgrid .ui-state-highlight { background: yellow; }
In my jqGrid everything works fine except for the form editor.. Why does the form editor display in top-middle of the screen?
Below is my code.
$(document).ready(function () {
var briefallocationid = $("#BriefAllocationId").val();
var updateDialog = {
url: '<%= Url.Action("UpdateRegionAndCity", "BriefAllocation") %>'
, closeAfterAdd: true
, closeAfterEdit: true
, modal: false,
top:0,
onclickSubmit: function (params) {
var ajaxData = {};
var list = $("#RegionAndCity");
var selectedRow = list.getGridParam("selrow");
rowData = list.getRowData(selectedRow);
ajaxData = { BriefAllocationId: briefallocationid };
return ajaxData;
}
};
$.jgrid.nav.addtext = "Add";
$.jgrid.nav.edittext = "Edit";
$.jgrid.nav.deltext = "Delete";
$.jgrid.edit.addCaption = "Add City";
$.jgrid.edit.editCaption = "Edit City";
$.jgrid.del.caption = "Delete City";
$.jgrid.del.msg = "Delete selected City?";
$("#RegionAndCity").jqGrid({
url: '/BriefAllocation/GetRegionAndCities/?briefId=' + briefallocationid,
datatype: 'json',
mtype: 'GET',
prmNames: {
briefId: briefallocationid
},
colNames: ['AllocatedRegionAndCitiesId', 'BriefAllocationId', 'LocationId', 'PlannerId', 'Region', 'Budget'],
colModel: [
{ name: 'AllocatedRegionAndCitiesId', index: 'AllocatedRegionAndCitiesId', width: 100, align: 'left', /* key: true,*/editable: true, editrules: { edithidden: false }, hidedlg: true, hidden: true },
{ name: 'BriefAllocationId', index: 'BriefAllocationId', width: 150, align: 'left', editable: false, edittype: 'text', editrules: { required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'LocationId', index: 'LocationId', width: 300, align: 'left', editable: true, edittype: 'text', editrules: { required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'PlannerId', index: 'PlannerId', width: 150, align: 'left', editable: true, edittype: 'text', editrules: { required: false} },
{ name: 'Region', index: 'Region', width: 100, align: 'left', editable: true, edittype: 'text', editrules: { required: true }, formoptions: { elmsuffix: ' *'} },
{ name: 'Budget', index: 'Budget', width: 100, align: 'left', editable: true, edittype: 'text', editrules: { required: true }, formoptions: { elmsuffix: ' *'} },
],
pager: $('#listPager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'AllocatedRegionAndCitiesId',
sortorder: "asc",
viewrecords: true,
imgpath: '/scripts/themes/steel/images',
caption: '<b>Regions And Cities</b>',
ondblClickRow: function (rowid, iRow, iCol, e) {
$("#RegionAndCity").editGridRow(rowid, prmGridDialog);
}
}).navGrid('#listPager', { edit: true, add: true, del: true, refresh: true },
updateDialog,
updateDialog,
updateDialog);
});
</script>
Also included following files:
<link href="../../Content/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<link href="../../Scripts/themes/grid.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.jqGrid.js" type="text/javascript"></script>
<script src="../../Scripts/js/jqModal.js" type="text/javascript"></script>
<script src="../../Scripts/js/jqDnR.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.maskedinput-1.2.2.min.js" type="text/javascript"></script>
<script src="../../Scripts/js/grid.locale-en.js" type="text/javascript"></script>
The table is declared as:
<div>
<table id ="RegionAndCity" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="listPager" class="scroll" style="text-align:center;"></div>
<div id="listPsetcols" class="scroll" style="text-align:center;"></div>
</div>
It was my mistake. I had not included jqModal.css. I had to change one property in it, that
is, position : absolute.
It is working now...