EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: fen9ye on June 18, 2014, 02:56:02 AM



Title: How can I use linkbutton in datagrid fomatter
Post by: fen9ye on June 18, 2014, 02:56:02 AM
<th field="isTaken" width="100" align="center" data-options="
   formatter:takenfomatter
">taken</th>

function takenfomatter(isTaken,row,index){
   var returnStr = "<a href=\"javascript:void(0)\" class='easyui-linkbutton' iconCls=\"icon-add\" onclick=\"javascript:alert('easyui')\">easyui</a>"
        return returnStr;
}


Title: Re: How can I use linkbutton in datagrid fomatter
Post by: jarry on June 18, 2014, 08:58:10 AM
The 'formatter' function only returns the formatted string. This function can't create any components automatically. You have to construct them manually. Please try to call .linkbutton(...) when loaded data successfully.
Code:
$('#dg').datagrid({
  onLoadSuccess:function(){
    $(this).datagrid('getPanel').find('a.easyui-linkbutton').linkbutton();
  }
});


Title: Re: How can I use linkbutton in datagrid fomatter
Post by: fen9ye on June 18, 2014, 07:05:03 PM
A thousand thanks.A new problem rise.I add the onclick function to the linkbutton as follows:
      function abc(isTaken,infoId){
         var index = $('#info_dg').datagrid('getRowIndex',infoId);
         $('#info_dg').datagrid('updateRow',{
            index: index,
            row: {
               isTaken : 1-isTaken
            }
         });
         $('#info_dg').datagrid('refreshRow',index);
      }
(linkbutton's text and icon depends on the isTaken).
After click,the text is correct but the linkbutton disapear.What shouldI do?


Title: Re: How can I use linkbutton in datagrid fomatter
Post by: jarry on June 19, 2014, 12:31:43 AM
After update a row, you need to call .linkbutton() to create the linkbutton again.
Code:
$('#dg').datagrid('getPanel').find('a.easyui-linkbutton').linkbutton();