@(Html.EJ().Grid<object>("Grid") .Datasource(ds => ds.URL("/Home/GetData").Offline(true)) .Columns(col => { col.Field("ID").IsPrimaryKey(true).Width(50).Add(); col.Field("Name").Width(20).Add(); col.Field("DateOfBirth").Format("{0:dd/MM/yyyy}").Width(20).Add(); col.Field("Address").Width(50).Add(); col.Field("MobileNumber").Width(50).Add();
}) ) <script>
$(document).ready(function () { // Binding pastable jquery plug-in $("#pastable").pastable({ OnPasteComplete: function (data) { // Ensuring pasted is an Excel data / Html Table data var jsonData = []; if (data instanceof Object) for (i = 0; i < data.length; i++) { jsonData.push(data[i]); }
$.ajax({ url: "/Home/Index", type: "POST", data: { pastedData: JSON.stringify(jsonData) }, success: function (gridData) { var gridObj = $("#Grid").data("ejGrid"); gridObj.dataSource(ej.parseJSON(gridData)); } }); }
});
}); </script>
</div> <b>Paste your Excel data here:</b> <br /> <div id="pastable" contenteditable="true" style="width: 0; height: 40px; padding-left: 250px;overflow: hidden; border: solid 1px; text-indent: 100px; font-size: 0;"> |
1. In which scenario you want validation?
2. Share more details about this query
Regards,
Jayaprakash K.
Jquery.pastable.js
var fnDelegate = function (fn, object) { return function () { return fn.call(object, null); } }
// This parse the html to Json object with assemption that first row is header function parseHtml(table) { var tr = table.find("tr"), headerTds = [], data = []; var hTd = tr.first().children("td, th");
for (var i = 0; i < hTd.length; i++) headerTds.push(hTd.eq(i).text());
for (var i = 1; i < tr.length; i++) { var json = {}, td = tr.eq(i).find("td, th"); for (var j = 0; j < td.length; j++) { json[headerTds[j]] = td.eq(j).text(); } data.push(json); } return data; } |