Inserito filtro categorie in lista notizie
This commit is contained in:
@@ -31,9 +31,17 @@ class DatatablesHelper {
|
||||
$models = array();
|
||||
if (array_key_exists("search", $_POST) && array_key_exists("value", $_POST["search"]) && strcmp(trim($_POST["search"]["value"]),"")!=0 ){
|
||||
$models = $dao->search($useModel, trim($_POST["search"]["value"]), $filter, $options);
|
||||
|
||||
$ret->recordsTotal = $dao->searchCount($useModel, trim($_POST["search"]["value"]));
|
||||
|
||||
$ret->recordsFiltered = $dao->searchCount($useModel, trim($_POST["search"]["value"]), $filter);
|
||||
}
|
||||
else {
|
||||
$models = $dao->query($useModel, $filter, $options);
|
||||
|
||||
$ret->recordsTotal = $dao->count($useModel);
|
||||
|
||||
$ret->recordsFiltered = $dao->count($useModel,$filter);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +53,9 @@ class DatatablesHelper {
|
||||
$ret->data[] = $result;
|
||||
}
|
||||
}
|
||||
$ret->recordsTotal = $dao->count($useModel);
|
||||
$ret->recordsFiltered = $dao->count($useModel,$filter);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
@@ -99,6 +108,20 @@ class DatatablesHelper {
|
||||
$buttonDiv.='<form action="" method="POST" style="display:none;"><input type="hidden" name="id" value=""/></form>';
|
||||
}
|
||||
|
||||
$additionalControlbarHtml = null;
|
||||
if (array_key_exists("additionalControlbarHtml",$htmlOpts)){
|
||||
$additionalControlbarHtml = $htmlOpts["additionalControlbarHtml"];
|
||||
}
|
||||
|
||||
$additionalPostFunction = null;
|
||||
if (array_key_exists("additionalPostFunction",$htmlOpts)){
|
||||
$additionalPostFunction = $htmlOpts["additionalPostFunction"];
|
||||
}
|
||||
|
||||
$initCompleteFunction = null;
|
||||
if (array_key_exists("initCompleteFunction",$htmlOpts)){
|
||||
$initCompleteFunction = $htmlOpts["initCompleteFunction"];
|
||||
}
|
||||
|
||||
$columns[] = array("label"=>"id","data"=>"id");
|
||||
|
||||
@@ -131,6 +154,11 @@ class DatatablesHelper {
|
||||
"serverSide": true,
|
||||
"ajax": {
|
||||
"url": "<?php echo GUIHandler::getBaseUrl();?>admin/tablesBackends/<?php echo $backendPage; ?>",
|
||||
<?php
|
||||
if (!is_null($additionalPostFunction)){
|
||||
echo '"data":'.$additionalPostFunction.",";
|
||||
}
|
||||
?>
|
||||
"type": "POST"
|
||||
},
|
||||
"columns": [ <?php echo implode(",", $jsCols);?> ],
|
||||
@@ -140,8 +168,18 @@ class DatatablesHelper {
|
||||
}
|
||||
?>
|
||||
"initComplete": function () {
|
||||
<?php
|
||||
if(!is_null($additionalControlbarHtml)){
|
||||
echo '$("div.'.$toolbarClass.'").prepend(\''.$additionalControlbarHtml.'\');';
|
||||
}
|
||||
?>
|
||||
$("div.<?php echo $toolbarClass;?>").prepend('<?php echo $buttonDiv;?>');
|
||||
<?php echo $buttonJs;?>
|
||||
<?php
|
||||
if(!is_null($initCompleteFunction)){
|
||||
echo $initCompleteFunction;
|
||||
}
|
||||
?>
|
||||
},
|
||||
"columnDefs": [
|
||||
{"className":"lastVisible","targets":[<?php echo sizeof($columns)-2;?>]},
|
||||
|
||||
@@ -32,9 +32,25 @@ $buttons = array(
|
||||
array("icon"=>"icon-medium-blue icon-remove","page"=>"deleteNotizie.php")
|
||||
);
|
||||
|
||||
$select = '<select id="categorySelect" name="category"><option value="0" selected="selected">Tutte</option>';
|
||||
foreach (NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
||||
$select.='<option value="'.$category.'">'.$data["label"]."</option>";
|
||||
}
|
||||
$select.="</select>";
|
||||
|
||||
$postFunction = 'function (d){ d.category = $("#categorySelect").val(); }';
|
||||
|
||||
$initComplete = '$("#categorySelect").change(function () {$("#datatable_0").DataTable().ajax.reload();});';
|
||||
|
||||
?>
|
||||
<div>
|
||||
<?php
|
||||
$details = DatatablesHelper::generateTable("notizieTableBackend.php",$columns,array("buttons"=>$buttons));
|
||||
$details = DatatablesHelper::generateTable("notizieTableBackend.php",$columns,array("buttons"=>$buttons, "additionalControlbarHtml"=>$select, "additionalPostFunction"=> $postFunction, 'initCompleteFunction'=>$initComplete));
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
|
||||
} );
|
||||
|
||||
</script>
|
||||
@@ -35,7 +35,13 @@ $exposedFields = array(
|
||||
"id"=>null
|
||||
);
|
||||
|
||||
$ret = DatatablesHelper::getResult($useModel, $permissionFlagRequired, $exposedFields, array("status"=>NotiziaModel::STATUS_ACCEPTED));
|
||||
$filter = array("status"=>NotiziaModel::STATUS_ACCEPTED);
|
||||
$categoryPost = PostHandler::get("category");
|
||||
if (!is_null($categoryPost) && array_key_exists($categoryPost, NotiziaModel::$NOTIZIE_CATEGORY)){
|
||||
$filter["category"] = intval($categoryPost);
|
||||
}
|
||||
|
||||
$ret = DatatablesHelper::getResult($useModel, $permissionFlagRequired, $exposedFields, $filter);
|
||||
if (property_exists($ret, "data") && sizeof($ret->data)>0){
|
||||
foreach ($ret->data as $key=>$ele ){
|
||||
$ret->data[$key]->sottotitolo = iconv('UTF-8', 'UTF-8//IGNORE', html_entity_decode($ret->data[$key]->sottotitolo));
|
||||
|
||||
Reference in New Issue
Block a user