jQgrid를 사용 중입니다. PHP의 콘텐츠를 작성하여 JSON으로보기로 보냅니다. 아래는 제가 현재 사용하고있는 PHP 코드의 조각입니다 :코드가 백엔드에서 생성되어 jQgrid에서 JSON으로 뷰로 전송 될 때 사용자 정의 포매터를 추가하는 방법은 무엇입니까?
$colFormats[] = [
'index' => 'actions',
'name' => 'actions',
'width' => 70,
'editable' => false,
'formatter' => 'show_btn',
'sortable' => false,
'align' => 'center'
];
foreach ($classMedata->getFieldNames() as $key => $value) {
$colFormats[] = [
'index' => $classMedata->getCollection().'.'.$value,
'name' => $value,
'width' => 100,
];
}
return $this->render('IntegrationBundle:api-logs:index.html.twig', [
'colFormats' => json_encode($colFormats),
'colNames' => json_encode($colNames),
]);
는 이것은 내가보기에있는 자바 스크립트 코드 :
<script type="text/javascript">
var show_btn = function (cellVal, options, rowObject) {
return '<input style="height:22px;" type="button" value="Show" onclick="" />';
};
$(function() {
$("#grid").jqGrid({
url: '/sf/api-logs',
datatype: "json",
colNames: {{ colNames|raw }},
colModel: {{ colFormats|raw }},
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,
sortable: true,
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
records: 'records',
cell: '',
repeatitems: false
},
loadComplete: function (data) {
if (data.records === 0) {
$("#load_grid").addClass("info_msg").html($("<span>", {
"class": "grid-empty",
"text": "No results were found."
})).delay(800).fadeIn(400);
}
}
});
});
</script>
PHP 뷰 내가 적절한 JS 코드를 볼 수 있습니다 렌더링 할 때 colNames
및 colModel
을 위해 :
colNames: ["Actions", "ID", "Object", ...],
colModel: [{
"index": "actions",
"name": "actions",
"width": 70,
"editable": false,
"formatter": "show_btn",
"sortable": false,
"align": "center"
},
{"index": "ApiLogs.id", "name": "id", "width": 100},
{"index": "ApiLogs.dataObject","name": "dataObject","width": 100}, ...
그러나 대신 콜 럼 Actions
에 렌더링 버튼이 표시의 나는 undefined
단어를 참조하십시오. 내 실수는 어디 있는지 모르겠습니다. 어떤 도움을 줄 수 있습니까?
나는 the docs과 this post을 읽었으며 나는 올바르게하고 있다고 생각하지만 위에 설명한 문제로 인한 것이 아닙니다.
을하십시오 확장있는 jqGrid에 대한 모든 질문에 ** 버전에 대한 정보를 포함하는이 작업을 수행하고 약 ** 포크 ** ([무료있는 jqGrid] (https://github.com/free-jqgrid/jqGrid), 상업용 [Guriddo jqGrid JS] (http://guriddo.net/?page_id=103334) 또는 이전 버전/이전 버전의 jqGrid (버전 4.7 이하). – Oleg