我已经实现了一个JQuery bootgrid。我的问题是,当我点击bootgrid中的click
输入时,我想忽略行select
事件。
这是我到目前为止所做的:
.on("click.rs.jquery.bootgrid", function (e, columns, row, target) {;
if(/* Clicked element is not a select input */) {
location.href = "/row?id=" + row.Id;
}
});
知道怎么做到这一点?我一直在努力解决这个问题。
编辑:为什么Alisson的回答不起作用。
当我这样做时:
.on("click.rs.jquery.bootgrid", function (e, column, row, target) {
console.log(row.IncidentId);
});
我可以获得IncidentId
,但是当我这样做时:
.on("loaded.rs.jquery.bootgrid", function () {
grid.find(".some-selector").on("click", function (e) {
// do what you need here...
var IncidentId = $(this).closest('tr').data('IncidentId');
location.href = "/row?id=" + IncidentId;
});
});
它不起作用,因为我无法以这种方式访问IncidentId
。
这是我的<thead>
:
<thead>
<tr>
@*<th data-column-id="IncidentId" data-visible="false">Id</th>*@
<th data-column-id="CaseNumber" data-order="asc">Case Number</th>
<th data-column-id="Title">Case Title</th>
<th data-column-id="EntrepreneurContact">Entrepreneur Contact</th>
<th data-column-id="Mentor">Mentor</th>
<th data-column-id="StatusReason">Status Reason</th>
<th data-column-id="CreatedOn">Created On</th>
</tr>
</thead>
我想要这个:
不是这个:
答案 0 :(得分:3)
您可以像使用Prime PrimeObject;
private void btnReadJson_Click(object sender, EventArgs e) {
try {
string json = File.ReadAllText(jsonFile);
PrimeObject = JsonConvert.DeserializeObject<Prime>(json);
dgvRamps.DataSource = PrimeObject.ramps;
lblColorGroup.Text = "Prime name: " + PrimeObject.name + " - Response Code: " + PrimeObject.response_code;
}
catch (Exception ex) {
MessageBox.Show("Error reading JSON file: " + jsonFile + Environment.NewLine + ex.Message);
}
}
private void dgvColor_SelectionChanged(object sender, EventArgs e) {
try {
if (dgvRamps.SelectedCells.Count > 0) {
int colorIndex = dgvRamps.SelectedCells[0].RowIndex;
dgvPoints.DataSource = PrimeObject.ramps[colorIndex].points;
}
}
catch (Exception ex) {
MessageBox.Show("SelectionChanged: Error: " + ex.Message);
}
}
事件一样使用,但与click
事件相结合可以阻止loaded
事件的传播:
select input
您需要绑定到网格var bootgrid = $("#grid1").bootgrid(config);
bootgrid.on("click.rs.jquery.bootgrid", function (e, columns, row, target) {
console.log('Incident Id: ' + row.IncidentId);
});
bootgrid.on("loaded.rs.jquery.bootgrid", function (e, c, rows) {
// avoid any element with "stop-click-event" class from triggering the event in the grid...
$(".stop-click-event").click(function(e) {
e.preventDefault();
e.stopPropagation();
});
});
事件中的click
,因为您可以确定选择输入等元素已存在于DOM中 ,并且每次重新加载网格后(至少对于ajax调用),bootgrid删除所有元素并使用新数据重新创建,loaded
将再次被触发,因此这些新元素将再次绑定。
而不是使用此loaded
事件,绑定到click.rs.jquery.bootgrid
,加载后,绑定到您需要的正确元素:
loaded
例如,如果你仍然需要为整行添加一个监听器,并希望避免点击var grid = $("#my-grid").bootgrid(config)
.on("loaded.rs.jquery.bootgrid", function () {
// find elements inside the grid, using some jQuery selector...
grid.find(".some-selector").on("click", function (e) {
// do what you need here...
var rowId = $(this).closest('tr').data('row-id');
location.href = "/row?id=" + rowId;
});
});
或button
,你可以这样做(仍然在< strong>已加载事件):
input