Hi Team,
I want to use Local header filtering with dropdown list.
But I can not find out a sample code about a location of dataModel is 'local'.
I will show my source code as follows.
The dropdown list which I want load date is dataIndx:sakuseisha.
Please show me a sample code in this case.
Regards,
Koichi
PQGrid Pro:4.0.2
WordPress:4.9.1
<script>
$(function () {
function generateordersdata() {
// prepare the data
var data = new Array();
<?php
$data = array();
$i = 0;
$newslist = get_posts( array(
'post_type' => 'product_forum', //特定のカスタム投稿タイプスラッグを指定
'posts_per_page' => -1 //取得記事件数
));
foreach( $newslist as $post ):setup_postdata( $post );
$row = array();
$row["number"] = $i;
$row["link"] = get_permalink();
$row["title"] = get_the_title();
$row["sakuseibi"] = get_the_date();
$row["sakuseisha"] = get_the_author();
$data[$i] = $row;
$i++;
endforeach; wp_reset_postdata();
?>
data = <?php echo json_encode($data); ?>;
return data;
}
var colM = [
{ title: "Title", width: 130, dataIndx: "title", dataType: "stringi", },
{ title: "Author", width: 150, dataIndx: "sakuseisha", dataType: "stringi",
filter: { type: "select",
condition: 'equal',
prepend: { '': '--Select--' },
valueIndx: "sakuseisha",
labelIndx: "sakuseisha",
listeners: ['change']
}
},
{ title: "Date", width: 80, dataIndx: "sakuseibi", dataType: "stringi", },
];
var dataM = {
location: "local",
sorting: "local",
dataType: "JSON",
method: "GET",
data: generateordersdata(),
};
var groupM = {
on: true,
dataIndx: ['cat'],
collapsed: [true],
dir: ['up'],
header: false,
headerMenu: false,
title: [
"{0} ({1})",
"{0} - {1}"
]
};
var obj = {
height: 600,
toolbar: {
cls: "pq-toolbar-search",
items: [
{
type: 'textbox',
label: 'Filter: ',
attr: 'placeholder="Enter your keyword"',
cls: "filterValue",
listener: { keyup: filterhandler }
},
{
type: 'select', cls: "filterColumn",
listener: filterhandler,
options: function (ui) {
var CM = ui.colModel;
var opts = [{ '': '[ All Fields ]'}];
for (var i = 0; i < CM.length; i++) {
var column = CM;
var obj = {};
obj[column.dataIndx] = column.title;
opts.push(obj);
}
return opts;
}
},
],
},
colModel: colM,
groupModel: groupM,
dataModel: dataM,
sortModel: {
single: false,
sorter: [{ dataIndx: 'cat', dir: 'up' }, { dataIndx: 'title', dir: 'up'}],
space: true,
multiKey: null
},
scrollModel: { autoFit: true },
numberCell: { show: false, resizable: true, title: "#" },
filterModel: { mode: 'OR', on: true, header: true, type: "local" },
selectionModel: { type: '', mode: 'single'},
showTitle: false,
resizable: true,
virtualX: true,
virtualY: true,
hwrap: false,
wrap: false,
columnBorders: false,
editable: false,
hoverMode: "row",
};
var $grid = $("#PQ_Grid").pqGrid(obj);
$( "#PQ_Grid" ).pqGrid({
rowDblClick: function( event, ui ) {
var url = ui.rowData['link'];
if ( url.substring(0,4) == "http" ) {
window.open(url);
}
}
});
});
</script>