我有Yii2分页的问题。我使用ListView小部件来显示数据。我也在我的模型中使用SetSort来排序数据。 我的搜索模型代码:
public function actionIndex()
{
$searchModel = new ItemsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());
return $this->render('index', [
'dataProvider'=>$dataProvider,
'searchModel'=>$searchModel,
]);
}
我知道这不是一个很好的决定将DESC和ASC逻辑划分为价格,但这是当前设计所需要的。我的控制器代码:
<? Pjax::begin(['id' => 'items', 'clientOptions' => ['method' => 'POST']]);?>
<?
$dataProvider->pagination = [
'defaultPageSize' => 8,
];
echo ListView::widget( [
'id'=>'items',
'pager' => [
'firstPageLabel' => "",
'disabledPageCssClass'=>'swiper-button-disabled',
'lastPageLabel' => "",
'nextPageLabel' => ">",
'prevPageLabel' => "<",
'maxButtonCount'=>0,
'nextPageCssClass'=>'total-button-next', 'prevPageCssClass'=>'total-button-prev',
'options'=>['id'=>'poplinks','class'=>'col-md-12 total-slider-orders margin-right-null padding-left-right-yes total-down-arrow']
],
'dataProvider' => $dataProvider,
'itemView' => '_item',
'summary'=>'',
] );
Pjax::end();?>
正如我所说,在视图中我使用ListView。这是我的观看代码:
{
"name": "ASP.NET",
"version": "1.0.0",
"devDependencies": {
"gulp": "3.8.11",
"gulp-inject": "1.5.0",
"gulp-util": "3.0.6",
"gulp-print": "1.1.0",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "1.2.0",
"gulp-load-plugins": "0.9.0",
"del": "1.2.0",
"wiredep": "3.0.0-beta",
"jshint": "2.8.0",
"jshint-stylish": "2.0.1"
}
}
var gulp = require('gulp'),
util = require('gulp-util'),
print = require('gulp-print'),
inject = require('gulp-inject'),
del = require('del'),
cssmin = require('gulp-cssmin'),
jshint = require('gulp-jshint')
uglify = require('gulp-uglify'),
wiredep = require('wiredep').stream,
bowerJson = require('./bower.json')
gulp = require('gulp'),
project = require('./project.json');
gulp.task('wiredep', function () {
log('Placing Bower Components from ' + paths.bowerComponents + ' in ' + paths.layoutPage)
return gulp
.src(paths.layoutPage)
.pipe(wiredep({
bowerJson: bowerJson,
directory: paths.bowerComponents,
ignorePath: '../..'
}))
.pipe($.inject(gulp.src([
paths.jsMain,
paths.jsContent])))
.pipe(gulp.dest(paths.layoutPage));
});
正如您所看到的,它在第一页上没有最后一个元素,在下一页上一切正常。我认为这是抵消,限制的事情。有人能告诉我,错误在哪里?谢谢!
答案 0 :(得分:1)
由于有很多关系,AR显示两个价格作为两个项目的项目,因此它在页面上显示7个项目而不是8.仅通过向搜索模型添加一行来解决它:
$query->groupBy('items.id');