所有边框颜色不变(仅限底部和右侧边框更改)

时间:2017-07-25 07:30:32

标签: html css jqwidget

在验证JqxGrid时,如果单元格具有空值,我想将单元格的边框更改为RED颜色。 我设法突出了细胞的边界,但只有底部和右边的边框是红色的,突出所有边界我缺少什么?

点击“点击验证”按钮,查看RED中错误编辑的单元格边框

jsfiddle

$(document).ready(function() {

  // prepare the data
  var data = new Array();

  var row1 = {};
  row1["firstname"] = 'Andrew';
  row1["secondname"] = 'A';

  var row2 = {};
  row2["firstname"] = '';
  row2["secondname"] = '';

  var row3 = {};
  row3["firstname"] = '';
  row3["secondname"] = 'C';

  data.push(row1);
  data.push(row2);
  data.push(row3);

  var source = {
    localdata: data,
    datatype: "array"
  };

  $("#jqxgrid").jqxGrid({
    width: "100%",
    source: source,
    autoheight: true,
    editable: true,
    editmode: 'selectedcell',
    selectionmode: 'singlecell',
    columns: [{
        text: 'First Name',
        datafield: 'firstname',
        width: 150,
        cellsalign: 'left'
      },

      {
        text: 'Second Name',
        datafield: 'secondname',
        width: 150,
        cellsalign: 'left'
      }
    ]
  });

  $("#btn").on('click', function() {
    var columns = ['firstname', 'secondname'];
    $.each(columns, function(colIndex, eachColumn) {
      $('#jqxgrid').jqxGrid('setcolumnproperty', eachColumn,
        'cellclassname',
        function(row, columnfield, value) {
          if (value == undefined || value.length == 0) {
            return 'erroredcolumn';
          }
        });
    });
  });

});
.erroredcolumn {
  border-color: red!important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/generatedata.js"></script>
<link href="https://jqwidgets.com/public/jqwidgets/styles/jqx.base.css" rel="stylesheet"/>
<script src="https://jqwidgets.com/jquery-widgets-demo/jqwidgets/globalization/globalize.js"></script>
<script src="https://jqwidgets.com/public/jqwidgets/jqx-all.js"></script>
<div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;">
  <div id="jqxgrid"></div>
</div>
<input type="button" id="btn" value="click to validate" />

2 个答案:

答案 0 :(得分:1)

尝试以下代码

        $(document).ready(function () {

            // prepare the data
            var data = new Array();
       
            var row1 = {};
            row1["firstname"] = 'Andrew';
            row1["secondname"] = 'A';
 						
            var row2 = {};
            row2["firstname"] = '';
            row2["secondname"] = '';

						var row3 = {};
            row3["firstname"] = '';
            row3["secondname"] = 'C';
            
            data.push(row1);
            data.push(row2);
            data.push(row3);

						var source = {
                localdata: data,
                datatype: "array"
            };
            
            $("#jqxgrid").jqxGrid({
                width: "100%",
                source: source,
                autoheight: true,
                editable: true,
       		    	editmode: 'selectedcell',
					    	selectionmode: 'singlecell',
                columns: [{
                    text: 'First Name',
                    datafield: 'firstname',
                    width: 150,
                    cellsalign: 'left'
                },

                {
                    text: 'Second Name',
                    datafield: 'secondname',
                    width: 150,
                    cellsalign: 'left'
                }]
            });
            
           $("#btn").on('click', function () {
           	var columns = ['firstname', 'secondname'];
            $.each( columns, function( colIndex, eachColumn ) {
			        $('#jqxgrid').jqxGrid('setcolumnproperty', eachColumn,
              			'cellclassname', function (row, columnfield, value) {
                    	if (value == undefined || value.length == 0) {
														return 'erroredcolumn';
											}
               			});
			         });
            });

        });
       .erroredcolumn {
             border-color: red !important;
             top:1px;
             border-width:1px 1px 1px 1px !important;
        }
        .jqx-grid-cell{
            
        }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/generatedata.js"></script>
<link href="https://jqwidgets.com/public/jqwidgets/styles/jqx.base.css" rel="stylesheet"/>
<script src="https://jqwidgets.com/jquery-widgets-demo/jqwidgets/globalization/globalize.js"></script>
<script src="https://jqwidgets.com/public/jqwidgets/jqx-all.js"></script>
<div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;">
    <div id="jqxgrid"></div>
</div>
<input type="button" id="btn" value="click to validate" />

答案 1 :(得分:1)

您正在使用position,因此当您应用border-color时,它会隐藏top-border,因为您未指定position top所以{{1}隐藏的灰色border-top

只需添加以下css

即可

<强> Fiddle link

border