【问题标题】:jsGrid - Style background group cellsjsGrid - 样式背景组单元格
【发布时间】:2021-07-01 04:20:17
【问题描述】:

我想改变两列的背景 (“姓名,年龄”)列 => 蓝色背景。 ("Address, Country") columns => 红色背景。

谢谢。

The cells I want to fill with background color.

 var clients = [
        { "Name": "Otto Clay", "Age": 25, "Country": 1, "Address": "Ap #897-1459 Quam Avenue", "Married": false },
        { "Name": "Connor Johnston", "Age": 45, "Country": 2, "Address": "Ap #370-4647 Dis Av.", "Married": true },
        { "Name": "Lacey Hess", "Age": 29, "Country": 3, "Address": "Ap #365-8835 Integer St.", "Married": false },
        { "Name": "Timothy Henson", "Age": 56, "Country": 1, "Address": "911-5143 Luctus Ave", "Married": true },
        { "Name": "Ramona Benton", "Age": 32, "Country": 3, "Address": "Ap #614-689 Vehicula Street", "Married": false }
    ];
 
    var countries = [
        { Name: "", Id: 0 },
        { Name: "United States", Id: 1 },
        { Name: "Canada", Id: 2 },
        { Name: "United Kingdom", Id: 3 }
    ];
 
    $("#jsGrid").jsGrid({
        width: "100%",
        height: "400px",
 
        inserting: true,
        editing: true,
        sorting: true,
        paging: true,
 
        data: clients,
 
        fields: [
            { name: "Name", type: "text", width: 150, validate: "required" },
            { name: "Age", type: "number", width: 50 },
            { name: "Address", type: "text", width: 200 },
            { name: "Country", type: "select", items: countries, valueField: "Id", textField: "Name" },
        ]
    });
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
<div id="jsGrid"></div>

【问题讨论】:

    标签: javascript jsgrid


    【解决方案1】:

    var clients = [{
        "Name": "Otto Clay",
        "Age": 25,
        "Country": 1,
        "Address": "Ap #897-1459 Quam Avenue",
        "Married": false
      },
      {
        "Name": "Connor Johnston",
        "Age": 45,
        "Country": 2,
        "Address": "Ap #370-4647 Dis Av.",
        "Married": true
      },
      {
        "Name": "Lacey Hess",
        "Age": 29,
        "Country": 3,
        "Address": "Ap #365-8835 Integer St.",
        "Married": false
      },
      {
        "Name": "Timothy Henson",
        "Age": 56,
        "Country": 1,
        "Address": "911-5143 Luctus Ave",
        "Married": true
      },
      {
        "Name": "Ramona Benton",
        "Age": 32,
        "Country": 3,
        "Address": "Ap #614-689 Vehicula Street",
        "Married": false
      }
    ];
    
    var countries = [{
        Name: "",
        Id: 0
      },
      {
        Name: "United States",
        Id: 1
      },
      {
        Name: "Canada",
        Id: 2
      },
      {
        Name: "United Kingdom",
        Id: 3
      }
    ];
    
    $("#jsGrid").jsGrid({
      width: "100%",
      height: "400px",
    
      inserting: true,
      editing: true,
      sorting: true,
      paging: true,
    
      data: clients,
    
      fields: [{
          name: "Name",
          type: "text",
          width: 150,
          validate: "required",
          css: "blue-cell",
          headercss: "blue-cell",
          filtercss: "blue-cell"
        },
        {
          name: "Age",
          type: "number",
          width: 50,
          css: "blue-cell"
        },
        {
          name: "Address",
          type: "text",
          width: 200,
          css: "red-cell"
        },
        {
          name: "Country",
          type: "select",
          items: countries,
          valueField: "Id",
          textField: "Name",
          css: "red-cell"
        },
      ]
    });
    <link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" rel="stylesheet" />
    <link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
    <div id="jsGrid"></div>
    
    <style>
      .jsgrid-row>.jsgrid-cell.blue-cell {
        background-color: blue ;
        color:white
      }
      
      .jsgrid-row>.jsgrid-cell.red-cell {
        background-color: red ;
        color:white
      }
    </style>

    结果:

    【讨论】:

    • 您可以在字段中使用css、headercss、filtercss、insertcss、editcss等。更多文档js-grid.com/docs/#fields
    • fields: [{ name: "Name", type: "text", width: 150, validate: "required", css: "blue-cell", headercss: "blue-cell", filtercss: "blue-cell" },
    猜你喜欢
    • 1970-01-01
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多