4

我目前正在使用js-grid从数据库查询返回的数据作为 Web 应用程序的一部分。所有功能似乎都按我的意愿运行;但是,当返回的数据导致整个网格的高度大于父元素的高度时,它会“溢出”。

例如,它应该如下所示:

在此处输入图像描述 但是,有了足够的数据,我得到:

在此处输入图像描述

我已将heightjsGrid 调用中的值设置为容器元素的值,并尝试使用 css 和 jQuery设置 aheight和css 值。max-height我还添加了 and 的溢出scrollauto但没有效果。

function surfaceDataGrid(message, recipient) {
var fieldData = JSON.parse(message.Data);
activeRequests.splice(0, activeRequests.length);
var columns = getColumns(recipient);
var Columns = columns.list.length;
var recipientElement = '#' + recipient;
var gridHeight = $(recipientElement).height();
var gridWidth = $(recipientElement).width();
$(recipientElement).html('<div id="jsgrid"></div>');
if (fieldData.length !== 0) {
    loggingAction('log', 'NOTIFICATION : Query returned ' + fieldData.length + ' rows of data. ');
    $(recipientElement).children('#jsgrid').jsGrid({
        data: fieldData,
        editing: false,
        fields: eval(columns),
        height: gridHeight,
        inserting: false,
        pageindex: 1,
        pagesize: 1,
        paging: false,
        selecting: "true",
        sorting: true,
        width: gridWidth,
    });
    var Rows = ($('.jsgrid-table tbody tr').length) - 3;
    $('.jsgrid-table').removeAttr('style');
    var gridheight2 = (gridHeight - 28) + "px";
    var headerwidth = (gridWidth / Columns) + 'px';
    $('.jsgrid-header-cell').width(headerwidth).width('28px');
    $('.jsgrid-grid-body').css('margin-top', '28px');
    $('.jsgrid .jsgrid-grid-body').css('height',gridheight2);
    $('.jsgrid-table').width(gridWidth + 'px');
    $('.jsgrid-grid-body .jsgrid-table').width(gridWidth + 'px').height(gridheight2 + 'px');
    $('.jsgrid-row').attr("tabIndex", "1");
    $('.jsgrid-alt-row').attr("tabIndex", "1");
}
else {
    $(recipientElement).children().remove();
    $(recipientElement).append('<div id="jsgrid"><h2 class="errorMessage" style="padding:1em;text-align:center;">No data returned.<br> Please resubmit!</h2></div>');
    $(recipientElement).fadeIn(fadeINtiming);
    loggingAction('log', 'NOTIFICATION : Query returned no data.');
}
$('tr').click(function () {
    var instantVariable0 = $('.jsgrid-header-row').parent().children()[0];
    var selectedType0 = $(instantVariable0).text();
    var instantVariable1 = $(this).parent().children()[0];
    gridValueSelected = $(instantVariable1).text();
    loggingAction('log', 'NOTIFICATION : A cell has been clicked');
    loggingAction('info', 'INFORMATION : Agent has selected ' + selectedType0.split(' ')[1] + ' value of "' + gridValueSelected + '".');
    $(this).addClass('selectedRow').siblings().removeClass('selectedRow');
});

}

4

1 回答 1

2

在这里,您可以使用解决方案https://jsfiddle.net/kL291xp5/39/

var data = [];

$("#jsGrid").jsGrid({
        height: 300,
        width: "100%",
        paging: false,
        autoload: true,
 
        fields: [
            { name: "Date", type: "textarea", width: 150 },
            { name: "User", type: "textarea", width: 150},
            { name: "Comment", type: "textarea", width: 150}
        ]
    });
    
$('button').click(function(){
	var comment = $('#comment').val().trim();
  if(comment.length > 0){
  	data.push({
    	Date: new Date(),
      User: 'ABC',
      Comment: comment
    });
    
    $("#jsGrid").jsGrid({
    	 controller: {
        	loadData: function() {
          	return data;
          }
        }
    });
    
    $('#comment').val('');
  }
});
.jsgrid-cell { 
    overflow: hidden; 
}

#comment{
  width: 300px;
  height:100px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.1/jsgrid-theme.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.1/jsgrid.css" rel="stylesheet"/>
<link href="https://code.jquery.com/ui/1.10.4/themes/redmond/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.1/jsgrid.js"></script>
<div id="jsGrid"></div>

<textarea id="comment"></textarea>
<button type="submit">Add Comments</button>

于 2017-08-04T03:54:02.280 回答