Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
i try to create table through jquery now i successfully display table and data
```
if (re.length > 0) {
    $("#services_schdulue").append
    $('#services_schdulue thead').append(
        "<tr><th>frequency</th><th>FDuration</th><th>FMil</th><th>Lperformed</th><th>Nddatetime</th><th>Ndmil</th><th>Rfrequ</th><th>Rduration</th><th>RMileage</th></tr>"
    );

    for (var i = 0; i < re.length; i++) {
        if (re[i] !== null) {
            $('#services_schdulue tbody').append(
                '<tr><td>' + re[i][0] +
                '</td><td>' + re[i][1] +
                '</td><td>' + re[i][2] +
                '</td><td>' + re[i][3] +
                '</td><td>' + re[i][4] +
                '</td><td>' + re[i][5] +
                '</td><td>' + re[i][6] +
                '</td><td>' + re[i][7] +
                '</td><td>' + re[i][8] +
                '</td></tr>');
        }
    }
}

var myTable = $('#services_schdulue').DataTable();
```
now i want to concatenation columns
want to concatenate these columns
1) frequency,FDuration,FMil and give one name in header "frequency"
2) Nddatetime,Ndmil and give one name in header "next service"
3) Rfrequ,Rduration,RMil and give one name in header "remaning"
how i do that ?


What I have tried:

Suupose i have data like this

IMAGE 1

http://i.imgur.com/MPdx38g.png

so i want data like this

IMAGE 2[^]
Posted
Updated 14-Oct-16 23:48pm

1 solution

Seems you don't know what <th> and <td> html tags do...

As documentation[^] says a <td> tag defines a standard cell in an HTML table. A <th> is header cell.

So... if you want to merge 2 columns (cells) into single one, you have to remove <th> and <td> tags from your code. For example:


PHP
//3 headers
$('#services_schdulue thead').append(
    "<th>one</th><th>two</th><th>three</th>"
);

//2 headers (second and third cell has been merged)
$('#services_schdulue thead').append(
    "<th>one</th><th>two and three</th>"
);



PHP
//three cells
for (var i = 0; i < re.length; i++) {
    if (re[i] !== null) {
        $('#services_schdulue tbody').append(
            '' + re[i][0] +
            '' + re[i][1] +
            '' + re[i][2] +
            '');
    }

//two cells (second and third has been merged)
for (var i = 0; i < re.length; i++) {
    if (re[i] !== null) {
        $('#services_schdulue tbody').append(
            '' + re[i][0] +
            '' + re[i][1] + ' ' + re[i][2] +
            '');
    }
 
Share this answer
 
v2
Comments
super_user 17-Oct-16 1:17am    
and how to give name to this + re[i][1] + ' ' + re[i][2] + .. means 1 has header abc and 2 have header def then how i give new name .. Info . and then i want to these hide these two columns 1 and 2 and display new column name with data "Info"
Maciej Los 17-Oct-16 1:50am    
Please, read my answer carefully, especially a first code block.
super_user 17-Oct-16 2:39am    
ok ... but thanku now done.. i have another question related to this can i ask

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900