How to change column header names in dataTable plugin

How to change column header names in dataTable plugin

tajtaj Posts: 20Questions: 5Answers: 0

I have tried below code in columnDefs as below
{ name: 'ColHeader_Name', targets: 0 }

Note : I have tried to search first of all but didn't get solution
link : https://datatables.net/forums/discussion/48621

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    The columns.title option is used to set the header title.

    Kevin

  • tajtaj Posts: 20Questions: 5Answers: 0
    edited July 2021

    please check attached screen shot that, highlighted part needs to be change
    also how arrange sorting images

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Looks like a styling issue. We will need a link to your page or a test case replicating the issues so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • tajtaj Posts: 20Questions: 5Answers: 0

    I got solution for adding column header for dynamically coming data as below,

    <script type="text/javascript">
    var columns = [];
            var colHeader = ['Required Col Header']
            
            $.ajax({
                url: '../Controller/Method1', type: "POST", processData: false,
                data: data, dataType: 'json',
                contentType: false,
                success: function (response) {
                    if (response != null || response != '') {
                        alert(response);
                        //debugger;
                        if (response == "File Saved Successfully and data uploaded successfully.") {
                            $.ajax({
                                type: "GET",
                                url: "../Controller/Method2",
                                success: function (data) {
                                    if (data != null) {
                                        //debugger;
    
                                        columnNames = Object.keys(data[0]);
    
                                        //Here I have pushed Required Column Headers 
                                        for (var i in columnNames) {
                                            columns.push({
                                                data: columnNames[i],
                                                title: colHeader[i]//col Header
                                            });
                                        }
    
                                        $("#divGridSales").css({ display: "block" });
    
                                        $('#tblViewPartDetails').DataTable({
                                            "processing": true, // for show progress bar
                                            "serverSide": false, // for process server side
                                            "filter": true, // this is for disable filter (search box)
                                            "orderMulti": false, // for disable multiple column at once
                                            "bDestroy": true,   //for reinitialize the datatable
                                            "data": data,
                                            "columns": columns
                                        });
                                    }
                                    else {
                                        alert('Something went to wrong!');
                                    }
                                }
                            });
                        }
                        else {
                            alert(response);
                        }
                    }
                    $("#file").val('');
                },
                error: onAjaxFailure
            });
    </script>
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Sorry about you having to post many times, something in your post triggered the spam filter. Thanks for reporting back the solution,

    Colin

Sign In or Register to comment.