:
когда пользователь нажимает на формулу 1 ссылки, я хочу перенаправить на http://en.wikipedia.org/wiki/7
вместо http://en.wikipedia.org/wiki/Formula 1
где 7 - id формулы 1
мой ответ JSON выглядит так:
{"rows":[{"id":7,"person":"Michael Schumacher","type":"Sport","name":"Formula 1"},
{"id":8,"person":"Lukas Podolski","type":"Sport","name":"Football"},
{"id":9,"person":"Blaise Pascal","type":"Sport","name":"mathematics"},
{"id":6,"person":"Albert Einstein","type":"Sport","name":"Physics"}]}
Код jqgrid - это
jQuery("#list2").jqGrid({
url:"***.****",
datatype: "json",
mtype: 'GET',
colNames:['Name','Category','Subcategory'],
colModel:[
{name:'person',index:'person', width:150},
{name:'type',index:'type', width:150},
{name:'name',index:'name', width:150,
formatter: function (cellvalue, options, rowObject) {
var cellPrefix = '';
return cellPrefix + '<a href="http://en.wikipedia.org/wiki/' + cellvalue + '">' +
cellvalue + '</a>';
}}
],
width:"647px",
caption:"How to create custom Unobtrusive links"
});
Вы можете просто заменить cellvalue
внутри кода настраиваемого форматирования на options.rowId
:
formatter: function (cellvalue, options) {
return '<a href="http://en.wikipedia.org/wiki/' + options.rowId + '">' +
cellvalue + '</a>';
}
Вы должны дополнительно исправить данные JSON и использовать "name":"Formula 1"
вместо "name"="Formula 1"
(то же самое для всех данных столбца "name"
). Вероятно, это просто печатает ошибку при подготовке вашего вопроса в stackoverflow.
Попробуйте следующее:
colNames:['Id','Name','Category','Subcategory'],
colModel:[
{name:'id',index:'id', width:150, hidden: true},
{name:'person',index:'person', width:150},
{name:'type',index:'type', width:150},
{name:'name',index:'name', width:150,
formatter: function (cellvalue, options, rowObject) {
var pageId = jQuery('[id="' + options.rowId + '"]').find('td:first').text();
return '<a href="http://en.wikipedia.org/wiki/' + pageId + '">' +
cellvalue + '</a>';
}
Попробуйте поместить скрытую правду и получить текст из этого td.