Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
grid view work done:
1 特性:支持id范围查询及排除查询
  • Loading branch information
php-cpm committed May 8, 2022
1 parent f2851d2 commit fedcd94
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
1 change: 0 additions & 1 deletion controllers/SupplierController.php
Expand Up @@ -44,7 +44,6 @@ public function actionIndex()
{
$searchModel = new SupplierSearch();
$dataProvider = $searchModel->search($this->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
Expand Down
41 changes: 35 additions & 6 deletions models/SupplierSearch.php
Expand Up @@ -50,21 +50,50 @@ public function search($params)

$this->load($params);


// grid filtering conditions
$operator = $this->getOperator($this->id);
$this->id = str_replace($operator,'',$this->id);
$query->andFilterWhere([$operator, 'id', $this->id]);

if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);

$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'code', $this->code])
->andFilterWhere(['like', 't_status', $this->t_status]);

return $dataProvider;
}
private function getOperator($qryString){
switch ($qryString){
case strpos($qryString,'<>') === 0:
$operator = '<>';
break;
case strpos($qryString,'!=') === 0:
$operator = '!=';
break;
case strpos($qryString,'>=') === 0:
$operator = '>=';
break;
case strpos($qryString,'<=') === 0:
$operator = '<=';
break;
case strpos($qryString,'=') === 0:
$operator = '=';
break;
case strpos($qryString,'>') === 0:
$operator = '>';
break;
case strpos($qryString,'<') === 0:
$operator = '<';
break;
default:
$operator = 'like';
break;
}
return $operator;
}
}
33 changes: 32 additions & 1 deletion views/supplier/index.php
Expand Up @@ -46,7 +46,38 @@
'contentOptions' => ['align'=>'center'],

],
'id',
[
'attribute' => 'id',
'value' => 'id',
'filter' => \yii\jui\AutoComplete::widget([
'model' => $searchModel,
'attribute' => 'id',
'clientOptions' => [
'minLength' => 1,
'autoFill' => true,
'source' => new \yii\web\JsExpression('
function(request, response) {
var suggestions = [];
var term = (request.term).match(/\d+/g)[0] || \'\'
jQuery.each([\'=\',\'>\',\'>=\',\'<\',\'<=\',\'!=\',], function(index, ele) {
suggestions.push({
label: ele + term,
value: ele + term
});
});
response(suggestions);
}'
),
'select' => new \yii\web\JsExpression('
function(event, ui) {
jQuery("#'.Html::getInputId($searchModel, 'id').'")
.val(ui.item.value);
jQuery("#supplier-table").yiiGridView("applyFilter");
}'
)
]
]),
],
[
'attribute' => 'name',
'value' => 'name',
Expand Down

0 comments on commit fedcd94

Please sign in to comment.