Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all 81690 articles
Browse latest View live

Responsive display removes phone country code control

$
0
0

Hello, I am using International telephone control https://github.com/jackocnr/intl-tel-input to allow users to set phone numbers with country codes. When allowing responsive DataTable, the control disappears from the input box.
I have two phone inputs "phone 1" & "phone 2" see attached photo, phone 1 already fits and the country code "displayed flag" works, however for "phone 2" the control disappeared.

Any recommendation or other phone country code plugins that you recommend?


Set checkbox to "checked" when a row is selected.

$
0
0

My table has a column with checkboxes in it, and I have it working correctly, returning the list of selected row ids to my Rails 5 controller. But I'd prefer to use the Select extension, and hide the checkbox column. I found a way to set the initial selection based on the checkbox state (might be clunky - any tips appreciated):

 table.rows().every( function () {
    if(this.data()[0].includes('checked="checked"')){
      this.select();
    } else {
      this.deselect();
    }
  });

Now, on submit, I want to set the checkbox state for all the rows based on their Select status. Not sure how to do that? I assumed I would just iterate the table again, but I don't see a is_selected() function for a row. And I don't know how to set the checkbox state for an input in a row as I iterate over them. I'm a js noob - more of a backend guy - so please forgive me it the answer is obvious.

Add as first row, and delete last row

$
0
0

I have a table that shows certain events live, ordered by timestamp descending. I initialize the table per JS object array (already sorted).

The the table is updated by AJAX. Since I enabled sorting on the datatable it works to add a new row (by using table.row.add(dataObject); ), but i also only want to display a certain amount of rows. Like when its more than 100, it shall the delete the row with the oldest timestamp.

And this is where my problem starts, the datatable sorting does not change the order of the data array, new rows are added to the end, so when i use table.row(99).remove(); it actually deletes the last inserted row.

I thought about disabling the datatable order functionality, but as far as i understood i cannot add new rows as the first row either.

Is my only solution to keep track of the data array and do all the sorting, inserting and deleting manually and then assign the data array again to the datatable? This seems like extremly bad for performance, since there can be multiple updates per second.

Did i get something wrong, or are there no other solutions? And if no, can anybody tell me about the performance impact this would have?

Problem with adding column values and rowgrouping

$
0
0

Hi!
Having an issue with the rowgroup feature. Trying to add the values of a calculated column but keep getting NaN in the grouping:

```$('#example').DataTable( {

    dom: "Bfrtip",
    ajax: "/api/cdi_masterpost",
    rowGroup: {
        startRender: null,
        endRender: function ( rows, group ) {
            var sum = rows
            .data()
            .pluck(7)
            .reduce( function (a, b) {
                return a + b;
            });

 
return 'Total Billable Hours for '+group+': '+
$.fn.dataTable.render.number(',').display( sum );
},
dataSrc: 'cdi_details.cdi_master_id'
},

    columnDefs: [

{
targets: 7, render: function (data, type, row) {
var hourscal = parseInt(data.cdi_details.hours);
var minutescal = parseInt(data.cdi_details.minutes);
var group = parseInt(data.cdi_details.group_count);
var groupminutes1 = hourscal * 60 / group;
if (minutescal !== 0) {
var groupminutes2 = minutescal / group;
} else {
var groupminutes2 = 0;
}
var totalgroupminutes = Math.round(groupminutes1 + groupminutes2);
if (totalgroupminutes >= 60) {
var totalhours = Math.floor(totalgroupminutes / 60)
} else {
var totalhours = 0;
}
return totalhours;
}
},
{
targets: 8, render: function (data, type, row) {
var hourscal = parseInt(data.cdi_details.hours);
var minutescal = parseInt(data.cdi_details.minutes);
var group = parseInt(data.cdi_details.group_count);
var groupminutes1 = hourscal * 60 / group;
if (minutescal !== 0) {
var groupminutes2 = minutescal / group;
} else {
var groupminutes2 = 0;
}
var totalgroupminutes = Math.round(groupminutes1 + groupminutes2);
if (totalgroupminutes >= 60) {
var totalsubminutes = Math.floor(totalgroupminutes / 60) * 60
} else {
var totalsubminutes = 0;
}
return totalgroupminutes - totalsubminutes;
}
}
],

    columns: [
          { data: "cdi_details.cdi_master_id" },
                    { data: "cdi_master.cdocdate" },
        { data: null, render: function ( data, type, row ) {
            // Combine the first and last names into a single table field
            return data.cdi_details.firstname+' '+data.cdi_details.lastname;
        }
        },
              { data: "cdi_details.service_class" },
                { data: "cdi_details.document_title" },
                    { data: "cdi_details.hours" },
                    { data: "cdi_details.minutes" },
                    {
                        data: null

                    },
                      {
                          data: null

                      },
                    { data: "cdi_details.group_count" }
    ],```

Any suggestions? I figured that it was probably the reference to column 7, but it allows me to change visibility of the column referencing it that way and run the function so not sure why it wouldn't work in the rowgrouping...?

Integration problem with Editor and Select2 plugin

$
0
0

I would like to integrate the select2 plugin with Editor but the following problems occur:

  1. What should the data of Office field be in order to Select2 plugin reads and inserts correct values?
  2. If you click on X in selected Tag, it does not cause removing this tag and the drop-down list stays open as well.
  3. After manually removing all picked tags, do nothing happens, I mean that no POST request is sent and there is still data in the field.

Below is an example (this is made according to your documentation) with the above problems.
http://webinsert.pl/bug_test/
I am asking for help in removing these problems. Thnx.

How do I translate custom buttons and custom buttons in a collection?

Bootstrap 3 styled colvis button flickers if inside button collection

$
0
0

Demo:

https://jsbin.com/notadabito/edit?

I notice it doesn't happen in the following three cases:

1) When the button collection around the buttons is removed.

2 When the "autoClose:" option of the button container is changed to false.

3) When an older version (1.2.2) of 'dataTables.buttons.min.js' is used instead of the current.

I have used other stylings without this problem happening.

Is there any way to to make the nested colvis button work properly while keeping the button collection/ autoclose: true/ current plugin version/bootstrap3 styling?

Buttons not displaying

$
0
0

Sorry in advance to ask a very common newbie question, but I did search the forums and didn't find anything that helped.

In an attempt to figure out why my buttons are not showing, I put together a very simple client-only HTML page, shown below, and am running it in Internet Explorer 11. I also confirmed that the following files (among many others) are present in directories underneath the location of the HTML page:

  • Scripts/jquery-3.1.1.js
  • Scripts/DataTables/jquery.dataTables.js
  • Scripts/DataTables/dataTables.buttons.min.js
  • Content/DataTables/css/jquery.dataTables.css
  • Content/DataTables/css/buttons.dataTables.min.css

The rest of the table functionality is working fine, it's just that the buttons are not showing. Any troubleshooting ideas are greatly appreciated.

P.S. Regarding the DataTables debugger, it's not clear to me how to use this with IE 11, since its debug console does not give me an opportunity to paste anything into it. I also searched for and couldn't find any further information on that in the forums.

<!DOCTYPE html>
<html>

<head>

    <!-- jQuery -->
    <script type='text/javascript' src='Scripts/jquery-3.1.1.js'></script>

    <!-- JS/CSS library for jQuery.DataTable -->
    <script type='text/javascript' src='Scripts/DataTables/jquery.dataTables.js'></script>
    <link href='Content/DataTables/css/jquery.dataTables.css' rel='stylesheet' type='text/css' />

    <script language="javascript" type="text/javascript">

        $(document).ready(function () {

            $('#MyTable').DataTable ({
                order: [[1, 'asc' ]],
                dom: 'Bflrtip',
                buttons: [ 'csv', 'excel' ]
            });
        });

    </script>

</head>

<body>

    <h1>Export Test</h1>

    <div style='width: 400px;'>
        <table id='MyTable' style='border: 1px solid black;'>

            <thead style='background-color: #DDD;'>
                <tr><td>ID</td><td>First</td><td>Last</td></tr>
            </thead>
            <tbody>
                <tr><td>1</td><td>Carol</td><td>Morin</td></tr>
                <tr><td>2</td><td>Jason</td><td>Toothaker</td></tr>
                <tr><td>3</td><td>John</td><td>Brooking</td></tr>
                <tr><td>4</td><td>Isaac</td><td>Oyinlade</td></tr>
                <tr><td>5</td><td>Rob</td><td>MacDonald</td></tr>
            </tbody>
        </table>
    </div>

</body>
</html>

How to make render() work independently when user- or application-filtering?

$
0
0

I just fell into a situation where the currently available set of values for type seems not enough to work as simply as it'd be possible.
Here is a pretty simple use case that illustrates the problem.

Having a column (say "allowed") containing a boolean value, which contains "0" or "1" (comes from a DB content).
Obviously it needs to be more friendly displayed so we'll do something like this:

var table = $('#example').dataTable({
  columnDefs: [{
    data: 'allowed',
    render: function (data, type, row, meta) {
      return data == '1' ? 'yes : 'no';
    }
  }]
});

Since we didn't do anything depending on type above, the user can type "yes" or "no" in the dedicated filter area to display only the allowed (respectively not-allowed) rows .

In the other hand, if for some reason the application must directly filter rows by itself, we can do for instance:

table.columns(<col index>).search('yes').draw;

So far so good.

Now if the application works in a multilingual context where a localize() function is available, the first scriptlet above becomes:

var table = $('#example').dataTable({
  columnDefs: [{
    data: 'allowed',
    render: function (data, type, row, meta) {
      return localize(data == '1' ? 'yes : 'no');
    }
  }]
});

Then user filtering keeps working fine, wether using "yes|no", "si|no", "oui|non", and so on.
But... now application filtering works only when the current language is English!

So one immediate obvious solution is to also change the second scriptlet accordingly:

table.columns(<col index>).search(localize('yes')).draw;

Sure then it works fine anew, but here is what I wanted to expose: isn'it too bad to have to use localize() again, while in this case a more immediate and elegant method would be to directly work with the original data value "0|1":

table.columns(<col index>).search('1').draw;

For this to work, it'd suffice to make render() work depending on its type argument.
But it's not currently possible: the "filter" type is the one used by DataTables both when responding to user-filtering and to column.search().
(BTW I guess that maybe user-filtering just uses column.search()...)

Here we retrieve what the doc says about the filter|search ambiguity.
So it'll be great if it could be uncoupled (may be by adding a new type value "search"?).

Thanks for your attention.

CSV Export only certain columns

$
0
0

i have a table with 5 columns and want to keep all 5 columns visible on the page but when the user clicks the CSV export button, i want to determine which columns will be on the excel sheet, namely I don't want the last column to show on the export. Is this possible?

td.details-control open an other table

$
0
0

I created a column td.details-control to show a to show something like a log in other table but i don't how to get td's id and filter the table by it. When I click on td.details-control shows all the table's values.

js
$('#cliente').on( 'click', 'td.details-control', function () {
document.getElementById('historico').style.display='block';

} );

var table = $('#venda').DataTable( {
    dom: 'Bfrtip',
    ajax: 'controller/controller_historico.php',
    columns: [
        {
            "data": "cliente.nome"
        },
        {
            "data": "vendedor.nome"
        },
        {
            "data": "venda.dta_venda"
        },
        {
            "data": "venda.valor_total_pago"
        },
        {
            "data": "venda.valor_total_liquido"
        }
    ],
    select: true,
    buttons: [
    ]
   }
} );

html

Histórico de compras do cliente

Cliente Vendedor Data da Compra Valor Total Pago Valor Líquido

Data Tables Search Not Working (PHP | Mysqli)

$
0
0

Hello All,

I have a Table, and i'm getting data from database using datatable. everything working fine but when i use search its not working. my code post search value on my serverside page and i Don't know what is mean in "bSearchable_" and "sSearch_". I'm stuck here from last 2 Days. Please Help me to out.


$sWhere = "";
$iColumnCount = count($aColumns);

if ( isset($input['search']) && $input['search'] != "" ) {
$aFilteringRules = array();
for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'false' ) {
$aFilteringRules[] = "".$aColumns[$i]." LIKE '%".$db->real_escape_string( $input['search'] )."%'";
}
}
if (!empty($aFilteringRules)) {
$aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
}
}

// Individual column filtering
for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
$aFilteringRules[] = "".$aColumns[$i]." LIKE '%".$db->real_escape_string($input['sSearch_'.$i])."%'";
}
}

if (!empty($aFilteringRules)) {
$sWhere = " WHERE ".implode(" AND ", $aFilteringRules);
} else {
$sWhere = "";
}

/**
* SQL queries
* Get data to display
*/
$aQueryColumns = array();
foreach ($aColumns as $col) {
if ($col != ' ') {
$aQueryColumns[] = $col;
}
}

$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".implode(", ", $aQueryColumns)."
FROM ".$sTable."".$sWhere.$sOrder.$sLimit;

$rResult = $db->query( $sQuery ) or die($db->error);

// Data set length after filtering
$sQuery = "SELECT FOUND_ROWS()";
$rResultFilterTotal = $db->query( $sQuery ) or die($db->error);
list($iFilteredTotal) = $rResultFilterTotal->fetch_row();

// Total data set length
$sQuery = "SELECT COUNT(".$sIndexColumn.") FROM ".$sTable."";
$rResultTotal = $db->query( $sQuery ) or die($db->error);
list($iTotal) = $rResultTotal->fetch_row();

How to display (open) a long table at a predetermined row ?

$
0
0

Reading through the forum I have not found a question (or answer) to this problem, I have a table with 450+ entries, but I can only link to the page holding the table, and this always starts from top.
Is there (a simple :-)) way to display a given line through a link on another page? (Is there a "trick" to create a link in another page, that opens the table to display lets say line 320 ? This is to free users from having to scroll through a lot of pages to arrive at the desired item - some users might even think the site is buggy, since the requested item does not show up immediately.
The table in question can be seen at: nslokal.ns-arkiv.dk/luftfoto/

Different fields for "create" and "edit"?

$
0
0

It's possible define different fields for "create" and "edit" buttons?

highlight in "table_1" all the rows which are present in "table_2"

$
0
0

Guys, who knows. I do not understand. Tell me please.
On one page 2 tables "table_1" and "table_2".
How I can highlight in "table_1" all the rows which are present in "table_2"?

Like on a picture.:


Change Casing before updating db

$
0
0

Hello Everyone, please how do i perform case changing on data submitted before calling ->process( $_POST ). That is to say i want to change all to ucwords() before i insert. Currently this is what am doing :

->fields( ... )
->validator( function ( $editor, $action, $data ) {
if ( $action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT ) {
foreach ( $data['data'] as $pkey => $values ) {
if ( $values === 'currency_name' ) {
$values['currency_name'] = ucwords(strtolower($values['currency_name']));
}
}
}
} )

```->process( $_POST )```
```->json();```

That is, i want to call ucwords() on on the data in currency_name . but its not working,

Please help me,

Add a custom footer on export

$
0
0

Does anyone have an example of how to add a custom footer when exporting to csv?

For example, after the table I want to add a blank row, then our company name.

Memory leak while using datatable in setTimeout() with 5 sec time interval

$
0
0

Hi,

I was using data table in setTimeout() with 5 sec as interval, and its observed that memory is increasing for each cycle.

Please help me on how to clear data table for each interval so that it won't increase memory.

Regards,
Santosh

column.search for numerical range

$
0
0

Hello,

I am new to datatables and am struggling on finding how to filter a column by a numerical range.

https://datatables.net/reference/api/column().search()

I have a column with pure numbers.

1
2
5
7
10
200
241
..etc

I have a filter textbox that a user can put a minimum amount, say 8. If 8 was answered i would want only rows with >= 8 to appear.

Filtering text works great with column.search(val ? '^' + val + '$' : '', true, false).draw(); However, i can't get the numerical >= to work.

Any help would be appreciated.
Thank you!

Different Tables From Different DB Tables On A Single Page

$
0
0

Hello guys, please forgive me if this question has been asked already in other form. I looked through the questions but couldnt find a similar one.

I want to build two different tables on a single page but each of these two tables will be populated with data coming from separate DB tables. I have created separate php files to handle data into and out of each tablle and i have two different tables on the HTML file each with a uniqiue id property. My problem now is with the js file. i cant just get my head around it.
This is what i have on the js file:

************************************************CODE BEGINS************************************************************
(function($){

$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'assets/datatable_assets/php/table.nestor_exchangerates.php',
table: '#nestor_exchangerates',
fields: [
{
"label": "Currency:",
"name": "exchangerate_currency"
},
{
"label": "Date:",
"name": "exchangerate_date",
"type": "datetime",
"format": "YYYY-MM-DD HH:mm:ss"
},
{
"label": "Amount:",
"name": "exchangerate_amount"
}
]
} );

var table = $('#nestor_exchangerates').DataTable( {
    dom: 'Bfrtip',
    ajax: 'assets/datatable_assets/php/table.nestor_exchangerates.php',
    columns: [
        {
            "data": "exchangerate_currency"
        },
        {
            "data": "exchangerate_date"
        },
        {
            "data": "exchangerate_amount"
        }
    ],
    select: true,
    lengthChange: false,
    buttons: [
        { extend: 'create', editor: editor },
        { extend: 'edit',   editor: editor },
        { extend: 'remove', editor: editor }
    ]
} );

} );

}(jQuery));

******************************************************* END CODE**************************************************************

but it doesnt work. Please help.

Thank you.

Viewing all 81690 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>