【发布时间】:2021-10-29 22:13:39
【问题描述】:
我目前正在使用免费的 JQGrid 4.6 版本和 Laravel 5.8,我开发的网格存在一些问题。所以这里是问题回顾:我想对一些包含来自我的模型Contact的动态属性的数据的列进行排序。
这是网格的列:
{name: "ID_PROJET", hidden:true},
{name: "DT_REEL_DON", align:'center',formatter:'date',sorttype : 'date', datefmt: 'd/m/Y',formatoptions: {srcformat:'Y-m-d',newformat: "d/m/Y"},excel:true, width:90},
{name:"LIBELLE_PROJ", excel:true,width:250},
{name:"contact.full_identite", excel:true},
{name:"MT_DON",formatter:'currency',align:'right',sorttype:'numeric',excel:true, width:60},
{name:"lib_type_don",excel:true, sortable:false},
{name:"lib_moyen_paiement",excel:true,width:60,sortable:false},
{name:"MAIL", excel:true},
{name:"ADRESSE1", excel:true},
{name:"CDPOST", excel:true,width:50},
{name:"COMMUNE", excel:true},
{name:"PAYS", excel:true,width:70},
{name:"SOLLICITE",excel:true,width:30},
{name: "action",template:"action",sortable:false, width: 75, align:"center",excel:false}
数据来自我序列化为 JSON 的这个请求:
$dons = $dons->with(['projet','contact'])
->join('projet','projet.ID_PROJET',"=",'don.ID_PROJET')
->join('contact','contact.ID_CONTACT',"=",'don.ID_CONTACT')
->orderBy($sidx,$sord)
->select('don.*','contact.MAIL','contact.ADRESSE1','contact.CDPOST','contact.COMMUNE','contact.PAYS','contact.SOLLICITE','projet.LIBELLE_PROJ')
->offset($start)->limit($limit)->get();
$sidx、$sord、$start 和 $limit 是用户在网格上执行操作(分页、排序等)时 JQGrid 发送的 GET 参数
效果很好,但问题出在contact.full_identite 列上,它不是我的contacts 表中的字段。这是一个像这样定义的laravel动态属性:
public function getFullIdentiteAttribute() {
// si entreprise
if ($this->TYPE_CONTACT_ == 1) {
return $this->ORGANISME;
}
// si particulier
else if ($this->TYPE_CONTACT_ == 2) {
return $this->NOM . ' ' . $this->PRENOM;
}
}
这个想法是如果这是一个特定的人,则返回一个人的全名,如果这是一个公司,则返回组织名称。
因此,当用户想要对此列进行排序时,我正在寻找一种在此动态属性上应用 orderBy 子句(在我上面的请求中)的方法。目前,我在NOM 字段上进行排序,它运行良好,但这不是我期望的结果。
这是我的contact 表的结构部分的屏幕截图:
提前感谢您的帮助,如果我不够清楚,请随时问我一些细节
【问题讨论】:
标签: php jquery laravel laravel-5 jqgrid