Add Link in datatable with ajax

Add Link in datatable with ajax

jarg5487jarg5487 Posts: 8Questions: 0Answers: 0
edited November 2012 in General
Hi,

I have a datatable in my website, I get the data with ajax:
[code]
$('#counties').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),''&sIndexColumn=CountyId&sTable=County"
});
[/code]

I need a hiperlink in the fourth field, I don't know make this.

Thanks

Replies

  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    use mRender along with fnCreatedCell for any styling
  • jarg5487jarg5487 Posts: 8Questions: 0Answers: 0
    Thanks man, but I'm start in datatables plugin, can you help me to put the source in my code?
    [code]
    $('#counties').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "bJQueryUI": true,
    "bAutoWidth": false,
    "sPaginationType": "full_numbers",
    "sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),'[mRender:Activate]'&sIndexColumn=CountyId&sTable=County"
    });
    [/code]
    But doesn't works.
    Thks and Sorry me.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Have a look at the documentation for mRender and fnCreatedCell and have a bash at it. Then link us to a test page showing what you've got if it still doesn't work.

    Allan
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    edited November 2012
    [code]

    $('#counties').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "bJQueryUI": true,
    "bAutoWidth": false,
    "sPaginationType": "full_numbers",

    // Add link - start
    "aoColumnDefs": [
    {
    "aTargets":[4],
    "fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
    {
    $(nTd).css('text-align', 'center'); // center the link
    },
    "mData": null,
    "mRender": function( data, type, full) {
    return 'Add';
    // Inplace of you can use
    }
    }
    ],
    // Add link - end

    "sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),'[mRender:Activate]'&sIndexColumn=CountyId&sTable=County"
    });
    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > return '

    Drop the '' from the return. The cell already exists :-)

    Allan
  • jarg5487jarg5487 Posts: 8Questions: 0Answers: 0
    mmmm Thanks .... But ...
    Jquery Source:
    [code]
    $('#counties').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "bJQueryUI": true,
    "bAutoWidth": false,
    "sPaginationType": "full_numbers",
    "aoColumnDefs": [
    {
    "aTargets":[3],
    "fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
    {
    $(nTd).css('text-align', 'center'); // center the link
    },
    "mData": null,
    "mRender": function( data, type, full) {
    return 'Add';
    }
    }
    ],
    "sAjaxSource": "ajaxbackend.php?function=Datatable&aColumns=CountyId,Name,(SELECT StateName FROM StateOrProvince WHERE County.StateId = StateId),''&sIndexColumn=CountyId&sTable=County"
    });
    });
    [/code]
    This is HTML source
    [code]

    County

    ID
    Name
    State
    Action



    [/code]
    But doesn't work yet ... Sorry :(
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    PLease give us a link then.

    Btw - passing SQL in sAjaxSource is very dangerous - a huge security whole in your app just waiting to be exploited!

    Allan
This discussion has been closed.