123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- Namespace.register("U.MD.UI.table");
- U.MD.UI.table = function (datasource, titles, css, parent) {
- U.MD.UI.table.thead(datasource, titles, css, parent);
-
- }
- U.MD.UI.table.thead = function (datasource, titles, css, parent, index, prows) {
- if (!index) {
-
- index = 1;
-
- prows = datasource.length;
- }
- var _table, _thead, _tr, _tbody;
-
- _table = $$("table", { style: {
- "text-align":"center",
- "position": "relative",
- "width": " 100%",
- "border-collapse": " collapse",
- "border-width": " 1px",
- "border-style": " solid",
- "border-color": " rgb(213, 213, 213)",
- "border-image": " initial",
- "display": "table"} }, parent);
-
- _thead = $$("thead", {}, _table);
-
- _tr = $$("tr", {}, _thead);
-
- for (var num in titles) {
-
- if (typeof titles[num] === "object") {
-
- $$("th", { innerHTML: titles[num].name, style: {
- "cssText": css[num],
- "padding": "10px 0",
- "font-weight": "normal",
- "border": "1px solid #d5d5d5"
- }, id: "th" }, _tr);
-
- } else {
- $$("th", { innerHTML: titles[num], style: {
- "cssText": css[num],
- "padding": "10px 0",
- "font-weight": "normal",
- "border": "1px solid #d5d5d5"
- }, id: "th" }, _tr);
-
- }
- }
- _tbody = $$("tbody", { style: { cssText: "width:100%;" }, id: "tbody" }, _table);
-
- U.MD.UI.table.tbody(_tbody, datasource, titles, css, index, prows);
-
- return _tbody;
-
- }
- U.MD.UI.table.tbody = function (parent, datasource, titles, css, index, prows) {
- var _tr, _td, _div, _neirong;
-
- for (var num = (index - 1) * prows; num < index * prows && num < datasource.length; num++) {
-
- if (num % 2 != 0) {
-
- _tr = $$("tr", { style: { cssText: "background-color: #FFF;" }, id: "tr" }, parent);
-
- } else {
- _tr = $$("tr", { style: { cssText: "background-color: #dde4ee;" }, id: "tr" }, parent);
-
- }
- for (var name in titles) {
-
- _td = $$("td", { id: "td" }, _tr);
-
- if (titles[name].content) {
- for (var k = 0; k < titles[name].content.length; k++) {
-
- _div = U.MD.UI.table.printDiv(_td, titles[name].content[k]);
-
- if (titles[name].content[k].onclick) {
- U.MD.UI.table.onclick(_div, datasource[num], titles[name].content[k].onclick);
- }
-
- }
- } else {
- _div = $$("div", { innerHTML: datasource[num][name], style: { "overflow": "hidden", "cssText": css[name]} }, _td);
- if (titles[name].id) {
- _div.id = datasource[num][titles[name].id];
- }
- }
- }
- }
- }
- U.MD.UI.table.pageTable = function (datasource, titles, css, prows, index, parent) {
- var _div = $$("div", { "style": {
- "left": "0px",
- "right": "0px",
- "width": "100%",
- "margin": "0 auto",
- "top": "200px" }
- }, parent);
-
- var _tdiv = $$("div", {}, _div);
-
- var _tbody = U.MD.UI.table.thead(datasource, titles, css, _tdiv, index, prows);
-
- var _pdiv = $$("div", { "style": {"width": "650px", "margin": "20px auto 0 auto"}}, _div);
- new U.UF.P.page(_pdiv, datasource.length, prows, index, function (page) {
-
- U.MD.UI.table.delChild(_tbody);
-
- U.MD.UI.table.tbody(_tbody, datasource, titles, css, page, prows);
-
- });
- }
- U.MD.UI.table.delChild = function (obj) {
- for (var num = obj.children.length - 1; num >= 0; num--) {
-
- obj.removeChild(obj.children[num])
-
- }
- }
- U.MD.UI.table.onclick = function (obj, datasource, fun) {
- obj.onclick = function () {
-
- fun(datasource);
- }
- }
- U.MD.UI.table.printDiv = function (parent, content) {
- var _div;
-
- if (typeof content.name == "string") {
-
- _div = $$("div", { "innerHTML": content.name }, parent);
- }
-
- if (typeof content.name == "object") {
-
- var _dd = content.name.cloneNode(true);
- parent.appendChild(_dd);
- _div = _dd;
- }
- return _div;
- }
|