在easyui的表格中,所绑定的数据是从数据库取得的数据,怎么将部分符合条件的数据显示为红色在线

在easyui的表格中,所绑定的数据是从数据库取得的数据,怎么将部分符合条件的数据显示为红色在线,第1张

datagrid 定义列有一个 styler 属性,,此属性值为一个函数,用于渲染单元格格式。

$('#dg')datagrid({

columns:[[

{field:'listprice',title:'List Price', width:80, align:'right',

styler: function(value,row,index){

if (value > 90){

return 'background-color:#ff0000;color:white;';

// the function can return predefined css class and inline style

// return {class:'c1',style:'color:red'}

}

}

}

]]

});

如果是使用html标签定义列也可以:

<th data-options="field:'unitcost',width:80,align:'right',styler: function(value,row,index){

if (value > 90){

    return 'background-color:#ff0000;color:white;';

    // the function can return predefined css class and inline style

    // return {class:'c1',style:'color:red'}

}

}">Unit Cost

</th>

可以看到效果:

获取当前的grid 循环判断获取需要的值 存进newData中 加载数据

var newData =[];

var gridData = $("#id")datagrid('getData');//获取当前grid的所有数据

for(var i =0;i<gridDatatotal;i++){

if (gridData[i]fieldId == '10') {

newDatapush(gridData[i]);

}

}

$("#id")datagrid('loadData',newData);

说明:

Bookmark:设置或返回当前的行标签号

DataGrid1Columns("ProductID")CellText(DataGrid1Bookmark)

返回当前行中字段为‘ProductID’的值。

DataGrid

被连接到一个数据库后,可能想要监视用户单击了哪一个单元。可以使用

RowColChange

事件——而不是

Click

事件。

如;

Private

Sub

DataGrid1_RowColChange(LastRow

As

Variant,

ByVal

LastCol

As

Integer)

DebugPrint

_DataGrid1Columns("ProductID")CellValue(DataGrid1Bookmark)

End

Sub

通过这个方法就能获得用户点击的行的某个值。

利用一下方法可以控制datagrid每列的宽度;

Dim

c

As

Column

Set

c

=

DataGrid1ColumnsAdd(DataGrid1ColumnsCount)

With

c

Visible

=

True

Width

=

1000

Caption

=

"我的新列"

DataField

=

Adodc1RecordsetFields("ProductName")Name

Alignment

=

dbgRight

End

With

下面的代码将删除被单击的列。

Private

Sub

DataGrid1_HeadClick(ByVal

ColIndex

As

Integer)

DataGrid1ColumnsRemove

ColIndex

End

Sub

easyui的datagrid的使用时后台得到的数据要转换成json格式的数据,lz最好把代码发上来,这样容易解决,不显示有很多种可能,也可能是没有数据或格式错误、datagrid属性写错了都有可能

以上就是关于在easyui的表格中,所绑定的数据是从数据库取得的数据,怎么将部分符合条件的数据显示为红色在线全部的内容,包括:在easyui的表格中,所绑定的数据是从数据库取得的数据,怎么将部分符合条件的数据显示为红色在线、easyui datagrid 中已经可以将数据全部显示出来,现在要在前端页面中查询指定条件,怎么在datagrid中实现、easyui中如何得到多行选中的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/9325723.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存