要添加到TableSorter的代码从特定列的列表中检索数据?

时间:2015-06-28 08:01:08

标签: jquery xml tablesorter modx

我在MySql和xml中有一系列34个区和34个邮政编码。用户输入信息并且仅选择1个区和1个邮政编码(还输入其他信息)。这将为邮政编码和地区留下33个空列。

我需要添加哪些代码才能使TableSorter显示(在子行中)只显示已输入的单个区域和邮政编码并忽略空列(区域和邮政编码)值?

我让TableSorter使用以下代码在前端显示我所需的大部分数据:

    <meta charset="utf-8">
    <!-- jQuery -->


<!-- Tablesorter: required -->
<link rel="stylesheet" href="../css/theme.blue.css">


<!-- Tablesorter: pager -->
<link rel="stylesheet" href="../css/jquery.tablesorter.pager.css">


    <script>
    $(function() {

    $(".tablesorter")
    .tablesorter({
    theme : 'blue',
    // this is the default setting
    cssChildRow: "tablesorter-childRow",

    // initialize zebra and filter widgets
    widgets: ["zebra", "filter", "pager"],

    widgetOptions: {
    // output default: '{page}/{totalPages}'
    // possible variables: {page}, {totalPages}, {filteredPages},                     {startRow}, {endRow}, {filteredRows} and {totalRows}
    pager_output: '{startRow} - {endRow} / {filteredRows} ({totalRows})', // '{page}/{totalPages}'
    pager_removeRows: false,
    // set number of rows to show; make sure to include this
    // value in the select options
    pager_size: 100,  
    // include child row content while filtering, if true
    filter_childRows  : true,
    // class name applied to filter row and each input
    filter_cssFilter  : 'tablesorter-filter',
    // search from beginning
    filter_startsWith : false,
    // Set this option to false to make the searches case sensitive
    filter_ignoreCase : true
  }

});
 // hide child rows
     $('.tablesorter-childRow td').hide();

  // Toggle child row content (td), not hiding the row since we are using rowspan
  // Using delegate because the pager plugin rebuilds the table after each page change
  // "delegate" works in jQuery 1.4.2+; use "live" back to v1.3; for older jQuery - SOL
  $('.tablesorter').delegate('.toggle', 'click' ,function(){

// use "nextUntil" to toggle multiple child rows
// toggle table cells instead of the row
$(this).closest('tr').nextUntil('tr.tablesorter-hasChildRow').find('td').toggle();

  return false;
  });

  // Toggle widgetFilterChildRows option
  $('button.toggle-option').click(function(){
var c = $('.tablesorter')[0].config.widgetOptions,
o = !c.filter_childRows;
c.filter_childRows = o;
$('.state').html(o.toString());
// update filter; include false parameter to force a new search
$('table').trigger('search', false);
return false;
  });
});
</script>


<div id="demo">

<div class="pager">
    <img src="../assets/images/first.png" class="first" alt="First" />
    <img src="../assets/images/previous.png" class="prev" alt="Prev" />
    <span class="pagedisplay"></span> <!-- this can be any element, including an input -->
    <img src="../assets/images/next.png" class="next" alt="Next" />
    <img src="../assets/images/last.png" class="last" alt="Last" />
    <select class="pagesize" title="Select page size">
        <option value="10">10</option>
        <option value="20">20</option>
        <option value="30">30</option>
        <option value="40">40</option>
        <option value="50">50</option>
        <option value="100">100</option>
    </select>
    <select class="gotoPage" title="Select page number"></select>
</div>

<table class="tablesorter">
<colgroup>
    <col width="85" />
    <col width="110" />
    <col width="110" />
    <col width="100" />
    <col width="100" />
</colgroup>
<thead>
    <tr>
        <th>Id No #</th>
        <th>Province</th>
        <th>Date</th>
        <th>Country</th>
        <th>Package Type</th>
    </tr>
</thead>
<tbody>
    <!-- First row expanded to reveal the layout -->
[[+innerrows.row]]
    </tbody>
</table>

   </div>

我想在下面添加代码,以便将子行作为唯一选区和邮政编码包含在内:

        <tr>
<td rowspan="4"> <!-- rowspan="4" makes the table look nicer -->
    <a href="#" class="toggle">[[+id]] - More info</a> <!-- link to toggle view of the child row -->
</td>
<td>[[+province]]</td>
<td>[[+date132]]</td>
<td>[[+country]]</td>
<td>[[+packagetype]]</td>
</tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">Customer Name</div><div>[[+yourname]]<br></div></td></tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">Phone Number</div><div>[[+phonenumber]]<br></div></td></tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">Email Address</div><div>[[+email128]]<br></div></td></tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">Company Name</div><div>[[+companyname]]<br></div></td></tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">Package Weight</div><div>[[+weight]]<br></div></td></tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">Package Width</div><div>[[+width]]<br></div></td></tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">package Height</div><div>[[+height]]<br></div></td></tr>
<tr class="tablesorter-childRow"><td colspan="5"><div class="bold">Details</div><div>[[+details]]<br></div></td></tr>

这是包含34个区和邮政编码的xml:

    <model package="shipsaveeng" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
<object class="ShipSave" table="shipsaveeng" extends="xPDOSimpleObject">
<field key="id" dbtype="int" precision="11" phptype="integer" null="false" default=""/>
<field key="province" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district1" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district2" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district3" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district4" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district5" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district6" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district7" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district8" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district9" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district10" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district11" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district12" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district13" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district14" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district15" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district16" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district17" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district18" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district19" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district20" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district21" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district22" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district23" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district24" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district25" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district26" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district27" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district28" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district29" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district30" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district31" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district32" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district33" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="district34" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="postcode1" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode2" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode3" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode4" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode5" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode6" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode7" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode8" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode9" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode10" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode11" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode12" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode13" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode14" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode15" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode16" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode17" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode18" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode19" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode20" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode21" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode22" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode23" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode24" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode25" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode26" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode27" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode28" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode29" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode30" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode31" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode32" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode33" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="postcode34" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="date132" dbtype="date" phptype="date" null="true" default="0000-00-00"/>
<field key="country" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="phonenumber" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="email128" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="companyname" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="packagetype" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
<field key="weightkgs" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="width" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="length" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="height" dbtype="decimal" precision="11.0" phptype="string" null="false" default=""/>
<field key="details" dbtype="text" phptype="string" null="false" default=""/>
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
    <column key="id" collation="A" null="false" />
</index>
    <aggregate alias="Resource" class="modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign" />
    <aggregate alias="Creator" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>

前端有一个表单,用户填写link to form。这会自动记录在数据库中。 数据库中的信息将自动显示在此页面的表格中link to table 用户还可以选择1个区和1个邮政编码,但是,在数据库中每个区和1个邮政编码就在那里。 我想在表格中只显示所选区域&amp;邮政编码。 所有其他区域和邮政编码也在他们自己的列中,但我希望代码忽略未选择的空字段。 一个用户可以选择district4&amp; postcode15,下一个用户可以选择分区28&amp; postcode14。 在前端桌上,我想在子行显示实际选择的区域&amp;邮政编码。

0 个答案:

没有答案