У меня есть сетка, в которую я могу добавить строки из внешнего интерфейса со следующим кодом, он работает нормально, но теперь мне нужно добавить проверку для дублирующих строк перед вставкой (то есть я не хочу добавлять повторяющиеся строки) :
$("#Submit_AddRow1").click(function () {
if (($('#txtPracticeArea').val() == '') && ($('#txtMarketArea').val() == '')) {
alert('Atleast One Value is mandatory!');
}
else {
//Reference the WebGrid.
var webGrid = $("#GridPractice");
//Reference the first row.
var row = webGrid.find("tr").eq(1);
//Check if row is dummy, if yes then remove.
if (($.trim(row.find("td:eq(0)").html()) == "") && ($.trim(row.find("td:eq(1)").html()) == "")) {
row.remove();
}
//Clone the reference first row.
row = row.clone(true);
//Reference the Practice Area TextBox.
var txtPracticeArea = $("#txtPracticeArea");
//Reference the Market Area TextBox.
var txtMarketArea = $("#txtMarketArea");
//Add the Practice Area value to first cell.
SetValue(row, 0, txtPracticeArea);
//Add the Market Area value to second cell.
SetValue(row, 1, txtMarketArea);
//Add the row to the WebGrid.
webGrid.append(row);
webGrid.show();
$('#gridPractice').show();
}
});
Вот моя Сетка
new { @id = "GridPractice", @class = "table table-sm
table-striped table-bordered table-condensed", @style = "width:100%" },
columns: grid1.Columns(
grid1.Column("PracticeArea", "Practice Area"),
grid1.Column("MarketArea", "Market Area"),
grid1.Column(format: @<text>
<a data-title="Are you sure to deactivate this Input?"
onclick="DeleteRow()"><i class="fa fa-trash" style="color:red"></i></a>
</text>, header: "Remove")));