简体   繁体   中英

using font-awesome in fnCreatedCell

Recently learned a new way to use data-attributes within a datatable.

Previously, I would code the columns in this manner (please note the font-awesome tags):

 "columns": [{ 
    "data": "",
    "fnCreatedCell": function (nTd, sData, oData, iRow, iCol)
    {
      $(nTd).html("<a href='#' title='Edit Account' class='modAccount' 
      data-voyid='"+oData.VOYID+"' data-servicename='"+oData.SERVICE_NAME+"' 
      data-vesselname='"+oData.VESSEL_NAME+"' data-voyage='"+oData.VOYAGE+"' 
      data-bound='"+oData.BOUND+"' data-cargoweek='"+oData.CARGO_WEEK+"' 
      data-cargoyear='"+oData.CARGO_YEAR+"' data-allocation='"+oData.ALLOCATION+"' 
      data-importvoyage='"+oData.IMPORT_VOYAGE+"' data-adddate='"+oData.ADD_DATE+"' 
      data-adduser='"+oData.ADD_USER+"' data-moddate='"+oData.MOD_DATE+"' 
      data-moduser='"+oData.MOD_USER+"'><i class='fa fa-edit fa-fw'> </i></a>");
    },

The method I just learned follows this format:

"columns": [{ 
    "data": "",
    "fnCreatedCell": function (nTd, sData, oData, iRow, iCol)
    {
       $('<a />', {
       'href': '#',
       'title': 'Edit Account',
       'class': 'modAccount',
       'data-voyid': oData.VOYID,
       'data-servicename': oData.SERVICE_NAME,
       'data-vesselname': oData.VESSEL_NAME,
       'data-voyage': oData.VOYAGE,
       'data-bound': oData.BOUND,
       'data-cargoweek': oData.CARGO_WEEK,
       'data-cargoyear': oData.CARGO_YEAR,
       'data-allocation': oData.ALLOCATION,
       'data-importvoyage': oData.IMPORT_VOYAGE,
       'data-adddate': oData.ADD_DATE,
       'data-adduser': oData.ADD_USER,
       'data-moddate': oData.MOD_DATE,
       'data-moduser': oData.MOD_USER,
       'text': '<i class="fa fa-edit fa-fw"> </i>' <-- does not work
       }).appendTo(nTd);
     }
   },

I had no problem bringing in the font-awesome icon with the first piece of code.

The second piece of code is where I need the icons now.

If you'll notice in the 'text' section in the second piece of code, I tried to pull in the font-awesome icons there. But on screen, I only see the code, not the icon.

How can I fix this to include the font-awesome icons?

Thank you.

您正在添加 HTML,因此您将字符串提供给html属性,而不是对象初始值设定项中的text

'html': '<i class="fa fa-edit fa-fw"> </i>'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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