Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all 2364 articles
Browse latest View live

editor $_POST data processing

$
0
0

I am having a problem with processing columns before updating in the Editor. We recently moved to Editor 1.5 and what we had earlier is no longer working. The goal is to hash a password as well as save a random salt value. Our original PHP code did something like this:
$_POST['data']['password'] = hash('sha512', $password . $random_salt);
$_POST['data']['salt'] = $random_salt;

However, when I look in the $_POST array now, it is structured like this:
$_POST[data][row_156][password] (note the additional level of the row #)
So the old code obviously doesn't work.

Is there a setting for a single edit that will leave out the row # level? All the forums and document I can find still recommend using
the structure of $_POST['data']['password'] but that isn't how the POST variables appear to be structured anymore.

Thanks in advance.


How to initialize options label/value with server reponse in Editor

$
0
0

Hi Allan,

I've been trying to find for a clean solution on how to initialize options fields in the editor with values returned from the database. In my mind when I specify the name locations I should be able to return for this field from the server an array with all the available labels and values from the server. In all the examples the only option is to hardcode/write the labels and values within the editor initialization as shown below:

editor.add( {
    type:  "select",
    label: "Locations:",
    name:  "locations",
    options: [
        { label: "Edinburgh", value: 51 },
        { label: "London",    value: 76 }
    ]
} );

Could you share the cleanest lines of code required to achieve this in the most current version of the editor? I hope it wont require tons of coding. In my mind this is a pretty common use cases and I have to believe the solution is quite straight forward.

Thanks

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Ajax request on preremove

$
0
0

Hi Allan,

I am trying to make an ajax request to delete some folders befores the delete execution but I am unable to get the row data. How can I rescue the row data? I have tried via row.table.field and editor.field('avschool.id').val(); but no neither of them gave me the id variable.

    editor
        .on( 'preRemove', function (data, type, row ) {
            var id = editor.field('table.id').val();

            $.ajax( {
                url: 'process_data.php',
                data:   {
                    var : id
                },
                type        : 'post'
                }).done(function(data){
               });
        } )

Thank you!

JS Nested Object Data format

$
0
0

Hi,

I'm trying to use a json format to populate a table and not having any luck. The data format is below . I tried using this example but it simply didn't work for my situation. Not sure why: https://datatables.net/examples/ajax/deep.html

var data = [
    {
        name: "index1",
        data: [
            {
                name: 'Cash',
                y: 35.61
            }, {
                name: 'Net Derivatives',
                y: 12.79
            }, {
                name: 'Non-US Sovereign Related',
                y: 11.77
            }, {
                name: 'Emerging Markets',
                y: 6.59
            }, {
                name: 'Agency Pass-Through MBS',
                y: 6.55
            }, {
                name: 'Commercial Mortgages',
                y: 5.97
            }, {
                name: 'Asset Backed Securities',
                y: 5.4
            }
        ]
    },
    {
        name: "index2",
        data: [
            {
                name: 'Cash',
                y: 35.61
            }, {
                name: 'Net Derivatives',
                y: 12.79
            }, {
                name: 'Non-US Sovereign Related',
                y: 11.77
            }, {
                name: 'Emerging Markets',
                y: 6.59
            }, {
                name: 'Agency Pass-Through MBS',
                y: 6.55
            }, {
                name: 'Commercial Mortgages',
                y: 5.97
            }, {
                name: 'Asset Backed Securities',
                y: 5.4
            }
        ]
    },
    {
        name: "index",
        data: [
            {
                name: 'Cash',
                y: 35.61
            }, {
                name: 'Net Derivatives',
                y: 12.79
            }, {
                name: 'Non-US Sovereign Related',
                y: 11.77
            }, {
                name: 'Emerging Markets',
                y: 6.59
            }, {
                name: 'Agency Pass-Through MBS',
                y: 6.55
            }, {
                name: 'Commercial Mortgages',
                y: 5.97
            }, {
                name: 'Asset Backed Securities',
                y: 5.4
            }
        ]
    }
];

The table has 4 columns with the first column using one set of the object name values, i.e. not repeated. The second, third and fourth columns would have the y values from index1, index2 and index3 respectively.

And here is how I am trying to configure it (I left out the other options not relevant here):

var tableOptions = {
    "columns" = [
        { "data": "0.data.name" },
        { "data": "0.data.y" },
        { "data": "1.data.y" },
        { "data": "2.data.y" }
    ],
    "data": tableData
}
$table.DataTable( tableOptions );

Any suggestions are appreciated.

Row details can be done easier

$
0
0

Hallo Allan,

I used the row details example for giving more details on my data.
https://datatables.net/examples/api/row_details.html

This can be done a little bit easier, with the advantage of passing through less initial data to datatables

in ruby on rails is this referring to the "show" section of a controller. for rendering a show pages without layout in rails, you just do render :show, :layout => false

    function virtual_aliases_show ( d ) {
        return '<div id="row_'+d.id+'"></div>';
    };

    function virtual_aliases_load_show (d) {
        $('#row_' + d.id).load('/virtual_aliases/'+d.id+'.html');
    };

    $('#virtual_aliases tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = virtual_aliases.row( tr );

        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child( virtual_aliases_show(row.data()) ).show();
            virtual_aliases_load_show(row.data());
            tr.addClass('shown');

        }
    } );

Way to enable client sided processing, but also enable deferLoading.

$
0
0

Hi,

Right now, deferLoading can only be enabled for server sided processing, and datatables options can not be changed once it has already been initialized.

Id like to know if there is a way to enable the features of deferLoading (to not send an ajax request for data until x event), but all future processing (like sorting, searching, etc) should be done client sided.

So in summary I'm looking for a way to enable this:

"serverSide": false,
"deferLoading": 0,

A better solution would be if there's a way to do all processing (searching, sorting, etc) client-sided, and all ajax requests for data would are controlled by one single event only; so searching or sorting will not trigger the ajax event. Only a certain event specified by me will trigger the ajax request.

Thanks.

Collapsible/Expanding rows passing row-contents onclick

$
0
0

Hi All,

I am trying to implement a datatable with expandible and collapsible rows similar to the code here :

```https://datatables.net/examples/api/row_details.html

I have gotten the code to expand and collapse the rows working but I'm experiencing difficulty in passing the values of the expanded row to my function when the details.control icon is clicked. eg. Upon clicking the expand icon(details-control) I'm trying to expand the row and populate it with data obtained via an ajax request dependent on some of the parent rows data. So some of the parent rows data needs to be passed to my ajax call. How do I obtain said rows data. My code is as follows below :

 $('#myTable').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = oTable.row(tr);
     // need to get row data here somehow
        var rowId = ?????

        if (row.child.isShown()) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        } else {
            // Open this row
            format(row.child,rowid);
            tr.addClass('shown');
        }
    });


    function format(callback, id) {
        $.ajax({
            url: "@Url.Action("foo", "bar")/"+ id,
            dataType: "json",
            complete: function (response) {
                var data = JSON.parse(response.responseText);
                var thead = '', tbody = '';
                for (var key in data[0]) {
                    //thead += '<th>' + key + '</th>';
                }

                $.each(data, function (i, d) {
                    for (var x = 0; x < d.length ; x++)
                    {
                        tbody += '<tr><td style="width:290px">' + d[x].Description + '</td><td style="width:210px">' + d[x].BalanceBroughtForward + '</td><td style="width:100px">' + d[x].Payments + '</td><td style="width:100px">' +
                      '</td></tr>';

                    }
                });
                callback($('<table>' + thead + tbody + '</table>')).show();
            },
            error: function () {
                $('#output').html('Bummer: there was an error!');
            }
        });

hide header if no results

$
0
0

Is there a standard way to not show header if theres no data in table


Ellipsis to truncate fails in Editor.

$
0
0

When I use the following code to render a column that is a not formatted, it works as expected;

data: "MaxText", className: "text-align-center", width: "35px", render: $.fn.dataTable.render.ellipsis(5, true) }

When I apply the same code to a column that is setup as a type:select column in the editor it fails.

What can I do to correct this?

Please let me know and thanks! :-)

Date format is not being correctly detected

$
0
0

I have a data coming from the server where a date column is of form: 1/25/2015 12:45:10 AM but is rendered in the table as /Date(1422168310723)/

I've implemented the Moment plug in and believe I'm correctly initializing because inserting debug alert:

    $.fn.dataTable.moment = function (format, locale) {
        alert(format);

will return 'M/D/YYYY'.

My ajax:

            "ajax": {
                "type": "POST",
                "url": '/admin/UsersDataHandler',
                "contentType": 'application/json; charset=utf-8',
                'data': function (data) {
                    data.affiliateId = DU.affiliateId;
                    return data = JSON.stringify(data);
                }

serverSide and processing both set to true;

To keep it simple, i'm not currently posting an entry for the column in "aoColumnDefs": and only use { 'data': 'DateCreated', "searchable": false } in the "columns" collection.

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

How to include line breaks when printing

$
0
0

I'm creating cell contends like:
"mRender": function (data, type, full) {
return full.LastName + ", " + full.FirstName + "<br>" + full.BillingEmail + "<br>" + full.Institution;

When printing or exporting the <br> is not honored. I tried inserting a javascript line break char (\n) without success. Any workarounds?

Excel button export column not in table but inside source data

$
0
0

Hi,
I need to add a field in my exported excel file.
I don't have this field (column) displayed in the table but it is contained in table source data array.
How can I include it in my export button configuration column selector?

This is my code portion:

[...]
"data": datiTabella,
buttons: [
            {
                extend: 'excel',
                text: 'Esporta Excel',
                className: 'btn btn-default',
                exportOptions: {
                    modifier: {
                        page: 'current'
                    },
                    columns: [ 3,4,5,6,7,8,9,10,11,12,13,14 ], // I don't know how to select data that is not on table
                    format: {
                        body: function ( data, column, row ) {
                           // here I have some column formatting...
                        }
                    }
                }
            }
        ]
[...]

Thank you,
alex

How to catch onChange event

$
0
0

Hello,

I'm trying to catch the onChange event for a field type: select.

I've attempted to use the sample code (shown below) however, it's triggered by several different events.

$( editor.field( 'myField' ).input() ).on( 'change', function () {
console.log( 'select2 change' );
} );

I found this sample here; https://datatables.net/forums/discussion/28670/how-to-trap-or-catch-onchange-events-from-select-or-select2

Anyway, when the page loads data via ajax or I select a new column the event is triggered. I was hoping to have the event triggered only when the user makes a new selection from the select list.

Do you have any suggestions on how I can achieve this behavior?

Please let me know and thanks,

~ Dave

submit full row data with select lists

$
0
0

Hello,

I have a table / editor with 5 columns set as type: select and the editor is set to use inline editing.

I wish to allow a user to make changes to one or more values (cells) in the row and then submit all changes at once.

The trouble I'm having is that the editor is only tracking 1 field change at a time. If I make a change to the value in column one (via the select list) and then move and change the value in column two... then save, only the last value changed is passed back.

The other changes are not being submitted with the save event.

What should I do to correct this behavior?

Please let me know and thanks,

~ Dave

Inline Editor select doesn't take option 0

$
0
0

Hello,

I'm experiencing a minor issue with inline editing and fields type: select. When the select list drops, option 0 (the first option) seems to already be selected. Selecting it will cause the list to collapse however, the change event is not fired.

It's similar to this post; https://datatables.net/forums/discussion/31210/datatables-inline-editor-select-does-not-select-current-value-or-submit-first-value

I'm using data tables 1.10.10 and Editor 1.5.4.

Has this bug resurfaced?

Please let me know and thanks,

~ Dave


lodash

$
0
0

Dattatables is using lodash . My question is how can i avoid loading loadsh if allready loaded

Invalid date with datetime-moment.js

$
0
0

Hi.

I have a databasefield with "YYYY-MM-DD" format.

In my js I have this:

$(document).ready(function() {

$.fn.dataTable.moment( 'DD.MM.YYYY' );

and in the data this:

data: "tm_mm_mitglieder.Geburtsdatum",
render: function ( data, type, row ) {
           return (moment(data).format("DD.MM.YYYY"));
    }

All is working but when the date in the database is empty or "0000-00-00" the table show "Invalid date" and the sorting is not working.

Then I have played with this:

data: "tm_mm_mitglieder.Geburtsdatum",
render: function ( data, type, row ) {
    var rowvalueallday = row["5"];

         if (rowvalueallday == '0000-00-00') {
         var gdat = '1900-01-01';
                       return gdat;
                      } else {
                         return (moment(data).format("DD.MM.YYYY"));
                      }

But it's not working.

How can I make the sort working correct and show "00.00.0000" or "Kein Datum angegeben" in the table?

Rappi

continuous font size control like in Excel

$
0
0

is this possible? I think it would be way cool to have a slide control like in the lower right corner in Excel, controlling font size in a continuous manner. (My tables can be very large and a feature like that would be very helpful.)

-Michael

Scrolling in input form

$
0
0

Hello,

I have a long input form to enter new data or to edit data: http://tinyurl.com/goyjxsb , and I would like to use the mouse wheel to scroll vertically. A scrollbar at the side of the popup window would also be helpful.

Is there a simple method to realize this?

Thanks,
Eberhard

Datatables - Buttons Applying Custom Style with Icon (Bootstrap)

$
0
0

Hi all,

I am using the datatables Buttons plugin to export to pdf. I am able to use custom styling to the button using the following code :

     "processing": true, // for show progress bar
        "serverSide": false, // for process server side
        "dom": '<"top"i>rt<"bottom"lp><"clear">',
        "scrollY": "500px",
        "buttons": [
            { "extend": 'pdf', "text":'Export',"className": 'btn btn-default btn-xs' }
        ],

and this code to append the button to a <span> :

      "initComplete": function() {
            oTable.buttons().container()
                .appendTo($('#btnPdf'));

However I am unable to find a way to use the bootstrap glyphicon with the button as I am using with my other input buttons as shown below :

    <button type="button" value="Search" id="btnSearch" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-search"></span>Search</button>
                                    <button type="button" value="Clear" id="btnClear" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span>Clear</button>
                                    <span id="btnPdf"></span>

Has anyone done something similar using the buttons plugin and icons/bootstrap glyphicons ?

Thanks in advance.

Viewing all 2364 articles
Browse latest View live