<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add/Remove dynamic rows in HTML table </title>
<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script src="utils/FetchUtil.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;
var cell3 = row.insertCell(2);
var element2 = document.createElement();
cell3.innerHTML = rowCount;
cell3.appendChild(element2);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i); rowCount--; i--;
}
}
}
catch (e) {
alert(e);
}
}
function deleteAllRows(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
table.deleteRow(i); rowCount--; i--;
}
}
catch (e) {
alert(e);
}
}
function getData(tableID) {
var table = document.getElementById(tableID);
var pn = "123456";
deleteAllRows(tableID);
var _oService;
var _sOrgName = "";
var _sServerUrl = Xrm.Page.context.getServerUrl();
alert(_sServerUrl);
var sFetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='contact'>" +
"<attribute name='fullname' />" +
"<attribute name='parentcustomerid' />" +
"<attribute name='telephone1' />" +
"<attribute name='address1_city' />" +
"<attribute name='emailaddress1' />" +
"<attribute name='adx_username' />" +
"<attribute name='createdon' />" +
"<attribute name='contactid' />" +
"<order attribute='createdon' descending='true' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<condition attribute='telephone1' operator='eq' value='" + pn + "'/>" +
"</filter>" +
"</entity>" +
"</fetch>";
_oService = new FetchUtil(_sOrgName, _sServerUrl);
var res = _oService.Fetch(sFetch);
for (var i = 0; i < res.length; i++) {
var fn = res[i].attributes["fullname"].value;
bindData(tableID, fn);
}
}
function bindData(tableID, ContactName) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;
var cell3 = row.insertCell(2);
var element2 = document.createElement();
cell3.innerHTML = ContactName;
cell3.appendChild(element2);
}
</script>
</head>
<body>
<input type="button" value="Get Data" onclick="getData('dataTable')" />
<input type="button" value="Add Row" onclick="addRow('dataTable')" />
<input type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<table id="dataTable" width="350px" border="1">
<tr>
<td>
<input type="checkbox" name="chk" />
</td>
<td>
1
</td>
<td>
</td>
</tr>
</table>
</body>
</html>
Hello copied ur code for dynamics generating of rows in the html page web resource,now i need to link an url to particular row of cells am not able to do that if u have anu idea plz help as soon as..
ReplyDeleteHello suresh nice code ,i generated a dynamic row and i need add a link(hyperlink) to the particular row of cells am nt able to do that if u have any idea plz help as soon as..
ReplyDelete