如何根据列 c#、mvc、json 的值在 jtable 中加粗一行

how to bold a row in jtable based on value of a column c#, mvc, json

我是 JTable 新手。我有 JSon 数据从控制器返回并将该数据加载到 JTable 中。 Json 数据有一个布尔列,比如 'ShowBold';我想在 JTable 中将 ShowBold 为 true 的整行加粗,但另一方面我不想在 JTable 中显示 'ShowBold' 。 我正在使用 c#、mvc 4 和 JSon 格式

的数据

请多指教。

我的代码如下:

<script language="JavaScript">
    $(document).ready(function () {
        $('#MyDiv').jtable({
            title: 'Client Data',
            paging: true,
            pageSize: 10,
            sorting:true,
            actions: { listAction: '/Home/getClientData/@Model.ID' },
            fields: { ClientID: {title: 'Client ID', width: '15%' },
            ClientName: {title: 'Client Name', width: '15%'},
            Address: {title: 'Address', width: '15%'},
            AmountDue: {title: 'Amount Due', width: '15%'},
            ShowBold: {title: 'Show Bold', width: '15%'}
        });

        $('#MyDiv').jtable('reload');

    });

</script>

<div id="MyDiv">Client data here.... </div>

只需从 jtable 初始化中删除列 ShowBold,并在每个列级别使用显示函数,您可以在其中设置单元格样式。

 $('#MyDiv').jtable({
    title: 'Client Data',
    paging: true,
    pageSize: 10,
    sorting:true,
    actions: { listAction: '/Home/getClientData/@Model.ID' },
    fields: { 
        ClientID: {
            title: 'Client ID', width: '15%',
            display: function (data) {
                if(data.record.ShowBold) 
                    return '<b>'+data.record.ClientID+'</b>'
                else
                    return data.record.ClientID;
            }
        },
        ClientName: {
            title: 'Client Name', width: '15%',
            display: function (data) {
                if(data.record.ShowBold) 
                    return '<b>'+data.record.ClientName+'</b>'
                else
                    return data.record.ClientName;
                }
        },
        Address: {
            title: 'Address', width: '15%',
            display: function (data) {
                if(data.record.ShowBold) 
                    return '<b>'+data.record.Address+'</b>'
                else
                    return data.record.Address;
             }
        },
        AmountDue: {
            title: 'Amount Due', width: '15%',
            display: function (data) {
                if(data.record.ShowBold) 
                    return '<b>'+data.record.AmountDue+'</b>'
                else
                    return data.record.AmountDue;
            }
        }
    }
});

这里是 ApiReference.