简体   繁体   English

JQuery DataTables和Jeditable-字段包含html,但不应包含html。 为什么?

[英]JQuery DataTables and Jeditable - fields contains html but should not. Why?

I am using DataTables and Jeditbale. 我正在使用DataTables和Jeditbale。 Everything seems to work well, however, for some reason when I double-click any field within the table, it contains HTML. 一切似乎都运行良好,但是由于某种原因,当我双击表中的任何字段时,它都包含HTML。 I have inserted the visual herein. 我在这里插入了视觉效果。 I have not tried anything to fix this problem as I cannot even understand how this would occur. 我还没有尝试解决此问题的方法,因为我什至不知道将如何发生。 I have googled the problem but most people who report a similar problem just report extra blank spaces; 我已经搜索了这个问题,但是大多数报告类似问题的人只报告了多余的空格。 not full html in fields. 字段中没有完整的html。 How can I fix this? 我怎样才能解决这个问题? If additional code required, can add in due course. 如果需要其他代码,可以在适当的时候添加。 在此处输入图片说明

Here is my table code: 这是我的表格代码:

<!-- start table listing -->
            <table id="myTable" class="stripe hover cell-border row-border">
                <thead>
                    <tr>
                        <th id="country_id">Country ID</th> 
                        <th id="country">Country Name</th>  
                        <th id="country_import">Import Commnents</th>
                        <th id="country_export">Export Comments</th>
                        <th id="country_date_created">Created</th>
                        <th id="country_date_updated">Updated</th>
                        <th id="">Updated by</th>
                        <th id="country_enabled">Enabled?</th>
                        <th id="">Actions</th>
                    </tr>
                </thead>

                <tbody>
                <?php
                    foreach ($query as $row ) {
                ?>
                    <tr <?php echo 'id="'.$row->country_id.'"'; ?> > 


                        <td>    
                            <?php echo $row->country_id; ?>
                        </td>


                        <td>    
                            <a class='table-action-deletelink' href='/admin/country_view/<?php echo ''.$row->country_id.''; ?> '><?php echo $row->country; ?></a>
                        </td>



                        <td>    
                            <?php echo $row->country_import_comments; ?>
                        </td>
                        <td>    
                            <?php echo $row->country_export_comments; ?>
                        </td>

                        <td>    
                            <?php echo $row->country_date_created; ?>
                        </td>

                        <td>    
                            <?php echo $row->country_date_last_updated; ?>
                        </td>

                        <td>    
                            <?php echo $row->country_updated_by; ?>
                        </td>






                        <td>    <?php 
                                if ($row->country_enabled == 1) {
                                    echo '<span class="glyphicon glyphicon-ok" aria-hidden="true" ></span>';
                                } else {
                                    echo '<span class="glyphicon glyphicon-remove" aria-hidden="true" ></span>';
                                } ?>
                        </td>




                        <td>


                        <!-- main container -->
                        <div class="dropdown">
                          <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
                            Dropdown
                            <span class="caret"></span>
                          </button>
                          <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                            <li role="presentation"><a role="menuitem" tabindex="-1" href="/admin/country_view/<?php echo ''.$row->country_id.''; ?>">View</a></li>
                            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Edit</a></li>
                            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Deactivate</a></li>
                            <li role="presentation"><a role="menuitem" tabindex="-1" href="/admin/country_delete/<?php echo ''.$row->country_id.''; ?> ">Delete</a></li>
                          </ul>
                        </div>


                        </td>

            </form>


                    </tr>
                    <?php } ?>
                </tbody>            
            </table>    
        </div>
    </div>
</div>

Here is my javascript that implements the table: 这是我实现表的javascript:

$(document).ready(function() {
    //sDeleteURL: "/Home/DeleteData.php"
    $('#myTable').dataTable().makeEditable( {
        // some basic config
        'bProcessing':      true, 
        'bServerSide':      true, 
         'sAjaxSource':     "admin/json_get_countries",

        stateSave:          true,
        "scrollCollapse":   true,
        "language": {
            "lengthMenu": "Display _MENU_ records per page",
            "zeroRecords": "Nothing found - sorry",
            "info": "Showing page _PAGE_ of _PAGES_",
            "infoEmpty": "No records available",
            "infoFiltered": "(filtered from _MAX_ total records)"
            }
    } );
} );  // end of on doc load

You're using jQuery DataTables Editable plugin which internally uses jQuery Jeditable plugin . 您正在使用内部使用jQuery Jeditable插件的 jQuery DataTables Editable 插件

According to Jeditable documentation (see Usage with Textile, Markdown, ReST, WiKi ), if field contains content other than plain text (HTML, Markdown, etc), you need to use loadurl parameter to load content in and sUpdateURL to save modified value. 根据Jeditable文档 (请参阅与Textile,Markdown,ReST,WiKi配合使用 ),如果字段包含的内容不是纯文本(HTML,Markdown等),则需要使用loadurl参数加载内容,并使用sUpdateURL保存修改后的值。

See Editable DataTable example - custom editors on how Engine version field is being edited and saved by using URLs specified in loadurl and sUpdateURL parameters. 请参阅Editable DataTable示例-自定义编辑器,以了解如何通过使用loadurlsUpdateURL参数中指定的URL编辑和保存Engine version字段。

You can make certain columns read-only and not-editable by defining aoColumns option and specifying null for corresponding column. 通过定义aoColumns选项并为相应的列指定null ,可以使某些aoColumns只读且不可编辑。 aoColumns is an array holding options for all columns in sequential order, length of this array must be equal to the number of columns in the original HTML table. aoColumns是一个数组,其中包含按顺序排列的所有列的选项,此数组的长度必须等于原始HTML表中的列数。

Example: 例:

$(document).ready( function () {
   $('#example').dataTable().makeEditable({
      sUpdateURL: "UpdateData.php",
      "aoColumns": [
            null,
            {
            },
            {
               indicator: 'Saving platforms...',
               tooltip: 'Click to edit platforms',
               type: 'textarea',
               submit:'Save changes',
               fnOnCellUpdated: function(sStatus, sValue, settings){
                  alert("(Cell Callback): Cell is updated with value " + sValue);
               }
            },
            {
               //indicator: 'Saving Engine Version...',
               tooltip: 'Click to select engine version',
               loadtext: 'loading...',
               type: 'select',
               onblur: 'cancel',
               submit: 'Ok',
               loadurl: 'EngineVersionList.php',
               loadtype: 'GET',
               sUpdateURL: "CustomUpdateEngineVersion.php"
            },
            {
               indicator: 'Saving CSS Grade...',
               tooltip: 'Click to select CSS Grade',
               loadtext: 'loading...',
               type: 'select',
               onblur: 'submit',
               data: "{'':'Please select...', 'A':'A','B':'B','C':'C'}",
               sUpdateURL: function(value, settings){
                  alert("Custom function for posting results");
                  return value;

               }
            }
      ]                          
   });
})

See answer to similar problem with Jeditable . 参见Jeditable对类似问题的回答 However this answer targets Jeditable only and not jQuery DataTables Editable plugin, so the code shown there doesn't apply, just the explanation. 但是,此答案仅针对Jeditable,而不针对jQuery DataTables Editable插件,因此此处显示的代码仅适用于说明,并不适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM