href for only field name start with certain name or description

href for only field name start with certain name or description

issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0
edited October 2017 in DataTables 1.10

hi,
I want to make some column in my datatable "href " with a condition if that column name start with some thing like a word "week" or "day"

again I am using a dynamic column creating when i get my query and send back to ajax,

Regards

This question has accepted answers - jump to:

Answers

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
    edited October 2017

    wrong answer, will give another one ....

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
    edited October 2017

    You have to do something like this, but my answer is not complete as I am threatening your data instead of the column name.

    Try something like this:

    columnDefs: [
        {render: function (data, type, full)
            {
                return (data.substring(0, 3) == "week")
                    ? `<a href="#YOUR_WEEK_LINK">data</a>`;`
                    : (data.substring(0, 2) == "day")`
                        ? `<a href="#YOUR_DAY_LINK">data</a>`;`
                        : data;
            },
            targets: YOUR_COLUMN_INDEX          //  field YOUR_FIELD
        }
    ]
    
  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
    edited October 2017

    Well, my above example was not fully complete. What you can do is add classes to your columns and then using my code example.

    Let's say give a class "week-field" to your week-columns and a class "day-field" to your day-columns.

    Then you can use the same render function as above, but you have to test on the class of the column and besides that, as it looks like you do not know which columns might have these classes, change "targets" in all your columns.

    I assume that at least on server-side you know what you are sending and thus are able to add classes to columns.

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Thank you for help, he is my example :neutral:

    http://jbmruby.com.cws17.my-hosting-panel.com/datatabledemo/Weekly_Dynamic_Details_report.php?screen_name=CNN&data_type=2&name=#hashtage

    what i am trying to do i have a dynamic data coming from the server with multi columns up to 52 columns. what i am doing to have a details page for each week on the page as a link as i said before.

    again thanks.

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Still waiting for help please, Thank you.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    So basically do you not want the null cells to have links? Just add a test for if ( ! data ) and have it return '';.

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Allan thank you for your response, Tester2017 give me the above solution it is not working for me, the data dynamic data coming from the server with multi columns up to 52 columns and can be one column, i need each column for the weeks to be a links but other columns no. my example show the results. i appreciate your help

    Thanks.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    i need each column for the weeks to be a links but other columns no

    Use the columnsDefs.targets option with a class name to target the weeks columns. Give each column for weeks a class name (such as weeks) and use targets: 'weeks'.

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Allan, do you have an example you can give to solve my problem. I read mostly all available example in the net looking for solution but may be "i ask to much". your help is great but still no thing i can find to work with me.

    Thank you.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓
  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0
    edited November 2017

    Allan, you are so great, your tool is great, and your support is great, Thank You. :D

    Just last thing if you allow me, how to get the column name to send back to the server.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Do you mean the title text for the column?

    $( table.column( index ).header() ).text();
    

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0
    edited November 2017

    allan I try that in many different way, totally not working. yes header fine or if possible the column name.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Can you link to a page showing the issue so I can help to debug it please?

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I don't actually see the code I suggested above on your page, but perhaps in this case it would be easiest to use:

    $('#Dynamic thead tr th').eq(2).text()
    

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Allan, you are amazing, thank you. but what about column index how to get it in
    my code because the column's are totally dynamic.

    in the line the number 2 can be up to 52 weeks.

    $('#Dynamic thead tr th').eq(2).text()

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I'd suggest using a class name:

    $('#Dynamic thead tr th.myClass').text()
    

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Allan, thank you for your help, it is work fine this is what i want. Regards for all.

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Allan, after i add some columns the value of the name of the column are the same for all. sorry for that but that happened, link sample:-

    http://jbmruby.com.cws17.my-hosting-panel.com/datatabledemo/Daily_Dynamic_Details_report.php?screen_name=_A__Dub&data_type=3&name=word

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yes - you would need to get each cell individually. The code I gave above will get the text for the first cell it finds. That's how jQuery's .text() method works.

    It sounds like you are going to need a loop counter of some kind.

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    I understand what you say, and am thankful for your help but seems to be we are stack somewhere. again the code is totally dynamic the number of columns start with min. 2 can be up to 52 weeks.

    in php i use a simple code that's different i know and what can be kind of loop works with my case ??????? i don't know.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Try this:

    render: function ( data, type, row, meta ) {
      var header = $('#Dynamic thead tr th').eq(meta.col).text()
      ...
    }
    

    That assumes that no columns will be hidden. If they are, you'd need to adjust for that using column.index().

    Allan

  • issamymansour@gmail.comissamymansour@gmail.com Posts: 24Questions: 3Answers: 0

    Allan, again thank you very much for your help and support keep going.

This discussion has been closed.