【问题标题】:Getting issues to remove rows in the datatable获取删除数据表中的行的问题
【发布时间】:2019-10-17 02:32:43
【问题描述】:

我正在尝试删除与第 0 列中的 job_titles 不匹配的每一行,但是当我尝试删除该行时,它不会删除任何内容,但是当我尝试检查它时出现。我究竟做错了什么?我尝试使用渲染来删除该字段,但它也不起作用

$(document).ready( function () {
    var keywords = ['aslr', 'ida pro', 'gdb', 'windbg', 'immunity debugger', 'boofuzz', 'peach fuzzer', 'winafl', 'python', 'assembly', 'penetration testing', 'exploits', 'metasploit', 'metasploit framework', 'ethical hacker', 'pentest', 'computer security', 'hacking', 'oscp', 'osce', 'osee', 'penetration testing', 'offensive security', 'mitre att&ck', 'vulnerability research', 'vulnerability researcher', 'fuzzing', 'clang', 'llvm', 'address sanitizer', 'afl', 'fuzzers','penetration tester']
    var job_title = ['penetration tester','penetration testing', 'offensive security', 'vulnerability researcher','software','security','developer','ethical hacker','cyberSécurité','threat','it Security','application security','information security','security engineer','product security','cyber security','software engineer','security analyst','consultant cyber sécurité','ingénieur cybersécurité','penetration test consultant','Penetrationstestare']
    var table = $('#example').DataTable({
        responsive: true,
        "ajax": {
            "url": "/index_get_data",
            "dataType": "json",
            "dataSrc": "jobs",
            "contentType":"application/json"
        },
        columnDefs: [{
            targets: 0,
            render: function (data) {
              if (job_title.some(word => data.includes(word)))
                return data
              else
                return data + "NOT_FOUND"
            }
        },{
            targets: 4,
            render: function (data) {
              if (keywords.some(word => data.includes(word)))
                return "<span class='label label-success'>FOUND</span>";
              else 
                return  "<span class='label label-danger'>NOT_FOUND</span>";

            }
        },{
          targets: 5,
            render: function (data) {
                return '<a href="'+data+'">Link</a>'
            }
        }],
        "columns": [
            {"data": "job_title"},
            {"data": "company"},
            {"data": "city"},
            {"data": "date"},
            {"data": "job_description"},
            {"data": "url"},
        ],
        rowCallback: function( row, data ) {
          let matches = 0;
          for (var i = 0; i < job_title.length; i += 1) {
            if (data.job_title.indexOf(job_title[i])) {
              matches++;
            }
            if(matches) {
              return data
            }else {
              return table.row($(this).parents('tr')).remove().draw(false)
            }
          }
        }
    });
    setInterval( function () {
        table.ajax.reload( null, false );
    }, 30000 );
} );

json

{city: "San Pedro Garza García, N. L.", company: "CEMEX", date: "hace 13 días", job_description: "we're looking for a talented professional to staff…sualization tools software.↵attention to details.", job_title: "(cen) process assessment consultant", …}
city: "San Pedro Garza García, N. L."
company: "CEMEX"
date: "hace 13 días"
job_description: "we're looking for a talented professional to staff the position of (cen) process assessment consultant.↵only resumes in english↵main accountabilities:↵the process assessment consultant will provide our stakeholders, management and audit committee an independent and objective evaluation and assessment concerning the level of exposure to risk throughout all the processes of the organization. to add value by helping all the operations to improve and strengthen the effectiveness of risk management, control systems and by sharing with them the best practices identified worldwide.↵challenges of the position:↵participate in the execution of the corporate annual audit plan:↵↵a) perform pre-designed audit tests to measure operational efficiency and compliance with cemex worldwide standards and international regulations.↵↵b) apply appropriate audit techniques to identify weaknesses in the internal control environment and report how effectively the existing controls are working in ordinary and special audits.↵↵c) lead audits by country or by process including resource and team management.↵↵d) responsible in the elaboration and presentation of audit reports to the highest levels of the company in which risks, policies non-compliances and any other deviations are informed.↵↵e) obtain remediation plans from the operations regarding observations raised in the audits and in some cases follow up commitments to correct such observations.↵↵f) after a certain tenure in process assessment, participate in training and coaching program for newest members in the department.↵collaboration in the identification of best practices during audit execution. identify best practices and local initiatives that were already tested, that could be shared annually worldwide for others to apply in their operations.↵administrative tasks.↵↵a) collaborate with management team in process assessment’s internal indicators monitoring, such as, internal travel expense budget, high level reporting (audit committee, executive committee) writing reviews, external surveys, report tracking, etc.↵↵b) design, modify and maintain the audit test inventory (pacs) of assigned processes as a result of changes or updates of the company’s internal control environment or structure.↵internal relations:↵interact with country managers , area vp´s and operational and administrative management in the different businesses and countries in which cemex operates.↵qualificationsrequirements:↵3+ years work experience in auditing or consulting, or in cemex’s own operation.↵sap knowledge. data analytics desirable↵audit-specific training is desirable (sarbanes oxley, fcpa, coso, risk management)↵experience in financial and process auditing.↵experience in cemex´s main processes such as cement, ready mix and aggregates operations, commercial, logistics, procurement, corporate finance and human resources as well as bso main functions like accounting, treasury and commercial administration in cemex or any other international company.↵oral and written communication abilities in order to prepare and communicate information to mid-upper management of the organization.↵willingness to travel locally and internationally for audit puposes (up to 45% of the year).↵technical skills:↵mba / msc and bachelors in engineering, accounting, finance or economics.↵↵acca qualification / cia / cfe desirable.↵spanish, english (bulats >= 75 or c1). desirable: french or german.↵sap, windows office. desirable: tableau, r, sql, python↵capable of working in a multicultural environment and multi level organization. experience in motivating, coaching, team building, knowledge transfer etc.↵self-driven, flexible, willingness to work in office and on the field.↵extract and analyze big data.↵able to use and interact with data management and visualization tools software.↵attention to details."
job_title: "(cen) process assessment consultant"
url: ["https://www.indeed.com.mx/rc/clk?jk=a4553da8d658e8f6&fccid=f7c3c2d35dd92dfe&vjs=3"]

【问题讨论】:

    标签: javascript jquery datatable


    【解决方案1】:

    我不是 100% 确定您的要求是什么,但是如果您只是 想要删除/隐藏数据表行,那么不要尝试删除 rowCallback 方法中的行,您可以使用数据表的 "dataSrc" 属性。

    你只需要过滤dataSrc里面的数据,就是这样。

    $(document).ready(function() {
        $('#example').dataTable( {
            "ajax": {
                "url": "https://www.mocky.io/v2/5da81a871200004d00edab46 ",
                "dataSrc": function(json) {
                    let data = json.demo;
                    //filtered whatever you want
                    var filtered = data.filter(function(value, index, arr){
                        return value[0] != 'Tiger Nixon';
                    });
                    return filtered;
                }
            }
        } );
    } );
    

    Json 数据

    {
      "demo": [
        [
          "Tiger Nixon",
          "System Architect",
          "Edinburgh",
          "5421",
          "2011/04/25",
          "$320,800"
        ],
        [
          "Garrett Winters",
          "Accountant",
          "Tokyo",
          "8422",
          "2011/07/25",
          "$170,750"
        ],
        [
          "Ashton Cox",
          "Junior Technical Author",
          "San Francisco",
          "1562",
          "2009/01/12",
          "$86,000"
        ],
        [
          "Cedric Kelly",
          "Senior Javascript Developer",
          "Edinburgh",
          "6224",
          "2012/03/29",
          "$433,060"
        ],
        [
          "Airi Satou",
          "Accountant",
          "Tokyo",
          "5407",
          "2008/11/28",
          "$162,700"
        ],
        [
          "Brielle Williamson",
          "Integration Specialist",
          "New York",
          "4804",
          "2012/12/02",
          "$372,000"
        ],
        [
          "Herrod Chandler",
          "Sales Assistant",
          "San Francisco",
          "9608",
          "2012/08/06",
          "$137,500"
        ],
        [
          "Rhona Davidson",
          "Integration Specialist",
          "Tokyo",
          "6200",
          "2010/10/14",
          "$327,900"
        ],
        [
          "Colleen Hurst",
          "Javascript Developer",
          "San Francisco",
          "2360",
          "2009/09/15",
          "$205,500"
        ],
        [
          "Sonya Frost",
          "Software Engineer",
          "Edinburgh",
          "1667",
          "2008/12/13",
          "$103,600"
        ],
        [
          "Jena Gaines",
          "Office Manager",
          "London",
          "3814",
          "2008/12/19",
          "$90,560"
        ],
        [
          "Quinn Flynn",
          "Support Lead",
          "Edinburgh",
          "9497",
          "2013/03/03",
          "$342,000"
        ],
        [
          "Charde Marshall",
          "Regional Director",
          "San Francisco",
          "6741",
          "2008/10/16",
          "$470,600"
        ],
        [
          "Haley Kennedy",
          "Senior Marketing Designer",
          "London",
          "3597",
          "2012/12/18",
          "$313,500"
        ],
        [
          "Tatyana Fitzpatrick",
          "Regional Director",
          "London",
          "1965",
          "2010/03/17",
          "$385,750"
        ],
        [
          "Michael Silva",
          "Marketing Designer",
          "London",
          "1581",
          "2012/11/27",
          "$198,500"
        ],
        [
          "Paul Byrd",
          "Chief Financial Officer (CFO)",
          "New York",
          "3059",
          "2010/06/09",
          "$725,000"
        ],
        [
          "Gloria Little",
          "Systems Administrator",
          "New York",
          "1721",
          "2009/04/10",
          "$237,500"
        ]
      ]
    }
    

    我将分享一个 JSFiddle 链接供您参考,我认为它会对您有所帮助。 链接:https://jsfiddle.net/amitmondal/28Lyndmv/28/

    如果您有任何困惑,请随时告诉我。

    数据表文档:https://datatables.net/reference/option/ajax.dataSrc

    【讨论】:

    • 我只是有些困惑,如何将我在数组中找到的函数与您的 `return value[0] != 'Tiger Nixon';` 集成?
    • 您必须使用 includes() 方法进行过滤。喜欢:返回 job_title .includes(data.job_title)。 job_title 是数组, data.job_title 是你的 job_title 值。明白了吗?
    猜你喜欢
    • 2011-05-10
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 2012-04-15
    • 2021-05-02
    • 1970-01-01
    • 2019-10-30
    • 2016-01-28
    相关资源
    最近更新 更多