我在 Ruby on Rails 中使用 JQGrid,它从控制器中提取数据,并且该控制器以 json 格式返回数据。下面是我的 JQuery 代码
<script type="text/javascript">
var list = null;
$(document).ready(function(){
grid = $("#list");
grid.jqGrid({
datatype: "json",
url:'/applications?'+new Date().getTime(),
height: <%= JQGRID_HEIGHT %>,
rowNum:<%= ROW_NUM %>,
rowList:<%= ROW_LIST %>,
viewrecords: true,
autowidth:true,
gridComplete: function() {
initLytebox();
common.jqGridComplete($(this));
initLytebox();
},
afterInsertRow: function(rowId) {
var action = grid.jqGrid('getRowData',rowId).action;
var cellValue = '<a href="/applications/'+rowId+'/edit"><img alt="Edit" src="/assets/edit.png" title="Edit"></a> '
cellValue += '<a href="javascript:void(0);" onclick="deleteApplication('+rowId+')" class = "delete_egress_group" id = "'+rowId+'">';
cellValue += '<img alt="Delete" src="/assets/delete.png" title="Delete"></a>';
grid.jqGrid('setRowData',rowId,{action:cellValue});
},
colNames:['Application Name','Description','Action'],
colModel:[
{name:'name',index:'name', width:"20%"},
{name:'description',index:'description', width:"70%"},
{name:'action',index:'action', width:"10%",search:false,sortable:false}
],
multiselect: false,
pager: '#pager',
toolbar: [true,"top"],
caption: "Applications" }
);
grid.jqGrid('navGrid', '#pager', {search: false, add: false, edit: false, del: false },{}, {}, {},
{ multipleSearch: true, overlay: false});
grid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: 'cn' });
grid.jqGrid('navButtonAdd', '#pager',
{
caption: "Add",title: "Add New",buttonicon: 'ui-icon-plus',
onClickButton: function () {window.location = "/applications/new";}
}
);
});
</script>
<select id="languages">
<option value="en">English (US)</option>
<option value="en-GB">English (GB)</option>
<option value="en-IN">English (IN)</option>
<option value="de">German</option>
<option value="ru">Russian</option>
</select>
<div style="width:100%">
<table id="list"></table>
<div id="pager"></div>
</div>
我已经从以下位置下载了多语言 js 文件并放置在我的应用程序的 JQGrid 文件夹下
http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/i18n/grid.locale-en-fixed.js
http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/i18n/grid.locale-ru-fixed.js
http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/i18n/grid.locale-de-fixed.js
现在我只想根据所选语言转换我的 JQGrid 的列标题和分页字符串。