I need to swap between actions based on a given condition in a jqGrid 4.4.1 grid. Take a look to the following image:
How it should works is:
- if Type is
api_response
then theactions
should be only the magnifier icon. - if Type is
api_request
then theactions
should be the second icon but magnifier shouldn't be there.
This is how I am creating the buttons:
$.fn.fmatter.btnFormatter = function (cellValue, options, rowData, addOrEdit) {
return '<a href="#">' +
'<img class="api_button" data-id="' + options.rowId + '" src="/images/icons/16x16/document_view.png" alt="Show API Response Data" title="Show API Response Data" />' +
'</a>' +
'<a href="/sf/api-logs/error/' + options.rowId + '">' +
'<img class="error_button" data-id="' + options.rowId + '" src="/images/icons/16x16/document_warning.png" alt="Show Errors" title="Show Errors" />' +
'</a>';
};
$(function () {
$("#grid").jqGrid({
url: '/api-logs',
datatype: "json",
colNames: $('#colnames').data('values'),
colModel: $('#colmodel').data('values'),
width: 980,
height: 300,
pager: "#gridpager",
toppager: true,
hoverrows: true,
shrinkToFit: true,
autowidth: true,
rownumbers: true,
viewrecords: true,
rowList: [10, 20, 50, 100],
data: [],
rownumWidth: 50,
gridview: true,
sortable: true,
rowattr: function (item) {
if (item.type === "api_response") {
return {"class": "api_response"};
} else if (item.type === 'api_request') {
return {"class": "api_request"};
}
},
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
records: 'records',
cell: '',
repeatitems: false
}
});
});
Of course the first column has the btnFormatter
applied.
How I can do this?