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

Record order changes by performing sort on multiple columns consecutively.

$
0
0

On this example http://live.datatables.net/

  1. Sort on name in descending order and then on office in descending order : 1st record is Zorita Serrano
  2. Sort on salary in descending order and then on office in descending order : 1st record is Gavin Cortez and 2nd is Zorita Serrano.

I have a use case when I want to have Zorita Serrano as 1st record when I sort on office column, no matter how many sorts I do previously.

What the option/implementation to have consistent grouping / ordering of records?

Thanks
Ankur Dohare


Processing Load very slow takes more than 30 seconds

$
0
0

Hello, I have been trying to load the content of a single query for days, I have tried both from the server side and directly and both do not work take the same.

I have incorporated the "scroller" plugin but it takes the same, someone can help me, I leave the code here, use php and codeigniter 3.

JS

var table = $('#datatabletransaction').DataTable({
    "deferRender":    true,
    "scrollY":        500,
    "scroller":       true,
    "responsive": true,
    "processing": true,
    "fixedHeader": true,
    "serverSide":true,
        "lengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "Todos"]],
        "ajax": {
            "url": mostrarcontenido,
            "type": "POST"
    },        
    language": {
          "url": "http://cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
    },
    "fixedColumns": true,
    "iDisplayLength": 5,
    "order": [[ 2, "desc" ]]
    });

Controller

public function mostrartablatransaccionestelefonos(){
      $this->load->model('tablas_model');
      $data = array();
      $list = $this->tablas_model->mostrar_registros_ventacompra($estado);
      foreach ($list as $person) {
          $row = array();
          $row[] = $person->num_factura;
          $row[] = $person->num_albaran;
          $row[] = $person->transacion;
          $row[] = $person->imei;
          $row[] = $person->nombre;
          $row[] = $person->fecha_registro;
          $row[] = $person->modelo;
          $row[] = $person->marca;
          $row[] = $person->color;
          $row[] = $person->memoria;
          $row[] = $person->precio_iva;
          $row[] = $person->precio_sin_iva;
    
          $output = array(
                  "data" => $data,
          );
          echo json_encode($output);

   }

Tab between columns not working

$
0
0

Good afternoon

I've set up an editable table with the options from this example: https://editor.datatables.net/examples/inline-editing/tabControl.html

When I click in a cell and then press the tab key the cell is still selected but the focus is then on the "back" button at the table bottom.

What I don't see in the example is following snippet to activate inline editing:

// Activate an inline edit on click of a table cell
$('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
    editor.inline( this, {
            submit: 'allIfChanged',
            onBlur: 'submit'
            } );
} );

Without it as in the example, I can't activate inline editing at all...

Searchpane issue with cascade and ajax reload

$
0
0

As mentioned in the Searchpane-feedback thread, there's a performance issue (pretty intense issue in fact), appearing when using cascading panes along with data.ajax.reload()

(see here for further details)

Pagination without recordsTotal / recordsFiltered

$
0
0

Hi,
Is there a method to ignore the need of recordsTotal and recordsFiltered? (serverSide paging)
I'm asking because i have a complex query and i don't need to know my totals (the data rapresent a system log, so is useless for user to know they have 100000 rows).
count all rows available is so time consuming that user would walk away (2 to 5 minutes).

Any suggestions?

ps: i just need "pagingType": "full", so no page number is required.

Thank you,
Diego

Grid resize is slow

$
0
0

This is 5000 rows X 20 columns.
I already using minified css files. But it is taking around 5 sec to resize.
Whole web app is unresponsive during these 5 seconds of resizing.

Is there a way to show loading overlay onBeforeResize and hide it in OnResize event.
Any suggestions how to keep browser more responsive during the resizing time?

Also browser is freezing during Redraw time. Any help with that?

Manually increase 100 record limit

$
0
0

Hi experts

Am working ASP/SQL website and redering database records using this awesome DataTables plugin.

But as i constated, it's fetching only 100 records. I have 1500+ records. But it only showing 100 records.

Showing 1 to 25 of 100 entries

How can i increase MANUALLY the limit ?

BTW: i cannot use the api, or php or Json. Am getting the records directly from DB to HTML

Trigger a row button programmaticaly on dblclick

$
0
0

Hello everyone,

I have created a table using datatable serverside.
In my columnDef, I define this columns :

{
                "render": function ( data, type, row ) {
                return '<a class="js-popin" href="{% url 'main:client_info' %}" data-popin-size="big" data-popin-type="card"><i class="c-fonticon__icon-plus"></i></a>'

                },
                "targets": 10,
                orderable:false,
            },

I can select a row by this way :

 $('#table_client tbody').on( 'dblclick', 'tr', function () {
        var id = table.row( table.$(this) ).data().id;
        alert( 'You clicked on '+id+'\'s row' );
       } );

What I would like to do is trigger the row button on double click on the corresponding row.
Is it something possible ?


Cannot edit row when the primary key is a string contains space

$
0
0

Hi,
I have a table that contains 2 columns:

+-------------+-----------+
| category    |  level   |
+-------------+-----------+
| Cat         |     1     |
| Cat A       |     2     |
| Cat B       |     1     |
| ....        | ...       |
+-------------+-----------+

on Client Side I create a simple editor:

editor = new $.fn.dataTable.Editor({
        ajax: url + "json",
        table: "#detail",
        fields: [
            {
                label: "Category",
                name: "category",
                type: "display"
            },
            {
                label: "level",
                name: "level"
            },
        ]
    });

on Server Side (PHP):

$DB  = $this->editorlib->getDatabase();
$ed = new Editor($DB, "category_table","category");
$ed->debug(true);
$ed->fields(
    Field::inst('category')->set(false),
    Field::inst('level')
);
$ed->process($_POST);
$ed->json();

When I tried to update Cat A level value to another value (3), the row is not updated but a new row with category value '0', and level value 3 inserted instead.

+-------------+-----------+
| category    |  level    |
+-------------+-----------+
| Cat         |     1     |
| Cat A       |     2     |
| Cat B       |     1     |
| 0           |     3     |
+-------------+-----------+

Debug log:

{
   "data":[
      {
         "DT_RowId":"row_0",
         "category":"0",
         "level":3
      }
   ],
   "debug":[
      {
         "query":"SELECT  category as \"category\" FROM  category_table WHERE category = :where_0 ",
         "bindings":[
            {
               "name":":where_0",
               "value":"0",
               "type":null
            }
         ]
      },
      {
         "query":"UPDATE  category_table SET  level = :level WHERE category = :where_0 ",
         "bindings":[
            {
               "name":":level",
               "value":"3",
               "type":null
            },
            {
               "name":":where_0",
               "value":"0",
               "type":null
            }
         ]
      },
      {
         "query":"SELECT  category as \"category\", level as \"level\" FROM  category_table WHERE category = :where_0 ",
         "bindings":[
            {
               "name":":where_0",
               "value":"0",
               "type":null
            }
         ]
      }
   ]
}

From the log above we can see that the binding for ':where_0' is incorrect. It should be "Cat A".

However if I edit the 'Cat' Category, it works fine.

If it's possible, I would like to avoid changing the database structure and add a new primary key.

Thank you.
Danny.

I have a function to DrawCallback.push. And i want to call inside dataTableExt.oSort ....

$
0
0

I have a function:

jQuery.fn.dataTableExt.oApi.fnFakeRowspan = function ( oSettings, iColumn, bCaseSensitive ) {
        ...
       oSettings.aoDrawCallback.push({ "fn": fakeRowspan3, "sName": "fnFakeRowspan3" });
    return this;
};

And i want to call inside:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
        "numeric-comma-pre": function ( a ) {
            var x = (a == "-") ? 0 : a.replace( /,/, "." );            
            
             ¿¿ jQuery.fn.dataTableExt.oApi.fnFakeRowspan(0);    ??

              cond = false;
          }
            
            return parseFloat( x );
        },

is there any idea?

How do I highlight cells in a specific row via the Excel Export?

$
0
0

I want to specify a row and a cell to highlight. I got the cell down, but how do I specify a row?
$('**Row index here?*** c[r^=\"D\"]', sheet).attr( 's', '20' );

Create Row With Custom Primary Key

$
0
0

Greetings
I use custom primary key, named key_id instead of the id column.
I use custom function to create this unique key_id, and using setFormatter on the field for that, while in the javascript side, I sent the key_id as a hidden field with value of null or false, just to make sure it will use the setFormatter function.
Example:

$e = Editor::inst($db, 'customers', 'key_id')
                ->fields([
                    Field::inst('customers.key_id')->setFormatter(function ($data) {                        
                       if($data){
                          //Not Modifying the KeyId in case of editting.
                          return $data;
                         }else{
                           //Generating New Id for Newly created Row, which has $data of false or null;
                           return SomeSpecialFunctionForRandomKeyId();
                        }
                    }),
                    Field::inst('customers.name'),

It is creating it fine, but the problem is, when I listen for the json of the creating request in javascript, I get empty data array. (I'm expecting to get the newly created row in the data array).
When I truned on debug mode for sql queries, I got two of them:
1- One for insertion, which is doing well.
2- Second one for selecting the created row, which bind the value of (ID OF CREATED ROW) to the key_id primary key column. That's why I get empty array I guess.
Any mistakes in my script or any suggestions ?

Update fields with PHP session variables

$
0
0

Hello!

I want to create a system to track when a record is created and modified. I have created all of the fields needed and made them read only so they can't be changed, I just can't seem to figure out the rest.

I'm using a ON UPDATE CURRENT_TIMESTAMP attribute for lastmodified, however I still need some way to handle the other three options.

I need to pass $_SESSION["username"] to the field createdby and the current time to createdat when a new entry is submitted.

I also need to pass $_SESSION["username"] to the field modifiedby whenever a change is made to a field.

Any suggestions on how this can be done easily?

.net oracle connection

$
0
0

I am trying to connect to an oracle database in my .net project. I am getting an error in the line

using (var db = new Database(settings.DbType, settings.DbConnection))

error is: unable to find the requested .net framework data provider. it may not be installed

do I need add a reference to something?

Export data hidden by Responsive whilst avoiding columns hidden by colvis

$
0
0

Exporting data hidden by Responsive whilst avoiding columns hidden by colvis

I've been looking in vain for a way to do this since "display: none" is used in both cases. columns: ':visible' neatly excludes the columns hidden by colvis but also misses the columns hidden by Responsive which I want to include. I've tried other selectors, combining options and a few other things but I can't get past exporting either none of the hidden columns or all of them. Is there a way to select the columns i want?


Column Search with Numeric Values

$
0
0

I currently have a DataTable that has a column containing a string of numeric values such in the format of '14,11,10'. They can only be a maximum of two digits long, but the number of values can vary. It could be a single value such as '11' or as many as four values within the string '16,14,10,21'.

In addition, I have a match handler and a select2 box that contains all of the potential number values. A user can either select to match 'Any', which will match every result if the number string contains at least one of the selected numbers. Selecting 'Match All' will only search for the specific combination, no matter the order of the numbers.

<select class="form-control form-control-alternative" id="syngery_match" name="syngery_match">
    <option value="any">Match Any</option>
    <option value="all">Match All</option>
</select>

<select class="form-control form-control-alternative synergies-multi select2-hidden-accessible" name="synergies[]" multiple="" id="synergies" data-select2-id="synergies" tabindex="-1" aria-hidden="true">
    <option value="1">NP</option>
    <option value="2">BL</option>
    <option value="3">X</option>
    <option value="4">BM</option>
    <option value="5">TN</option>
    <option value="6">DK</option>
    <option value="7">AD</option>
    <option value="8">WK</option>
    <option value="9">WM</option>
    <option value="10">RS</option>
    <option value="11">M</option>
    <option value="12">1T</option>
    <option value="13">TK</option>
    <option value="14">WC</option>
    <option value="15">SP</option>
    <option value="16">FB</option>
    <option value="18">HH</option>
    <option value="19">DZ</option>
    <option value="20">CP</option>
    <option value="21">HT</option>
    <option value="22">CS</option>
</select>

Match Any

I have this part working aside from one minor issue with the single digit numbers.

Example Input: [1,22,16]

if ($("#syngery_match").val() == "any")
{
    var any_string = $(this).val().toString();
    var select_snys = any_string.replace(',', '|');
    players_table.columns("#synergies_column").search(select_snys, true, false).draw();
}

Since 1 was included in the string of numbers, it returns rows that contain values such as 11,12,13....19, 21, etc. How would I go about altering my code so the rows returned have to contain the exact number in the string and not just a part of the number?

Match All

This part is also partially working. The only issue here is that the string of numbers entered only returns rows with the numbers in that exact order.

Target Row: [13,15,6]

Example Input: [6,13,15]
Example Input 2: [15,13,6]

The two example inputs return no results as the numbers were entered out of order compared to the column on the table.

else if ($("#syngery_match").val() == "all")
{
    var any_string = $(this).val().toString();
    players_table.column("#synergies_column").search(any_string, true, false).draw();
}

Hopefully I was able to explain my situation clearly enough. Any help would be appreciated!

Add customize function to DataTable print button *after* initialization?

$
0
0

I'm trying to customize a web app that allows custom javascript to be added.

I'm trying to set the CSS for the print button (https://datatables.net/extensions/buttons/examples/print/customisation.html), but I cannot set the "customize" parameter of the button, because the webapp has already initialized everything.

I can access the button through JavaScript, but I tried attaching a function like this:

$(document).ready(function() {
table.buttons('.buttons-print').customize = function(){ alert("TEST") };
});

but it simply doesn't work. I'm clearly missing something.

I tried checking the source code for the print button ( https://github.com/DataTables/Buttons/blob/master/js/buttons.print.js ) but that didn't clear anything up for me.

Does anyone know if what I'm trying to accomplish is possible?

FixedHeaders (v3.1.6): Any reference to original table?

$
0
0

I have some custom header-level elements that have behavior that I would like to maintain on the fixed header. Does anyone know if the created fixed position table has any reference to the dataTable it originated from? I haven't noticed anything that consistently ties it to the table that created it, so far. Just want to make sure there isn't anything out-of-box that I'm missing before I create my own solution. Thanks in advance!
DataTable version: 1.10.20

dynamic datasource asp.net mvc

$
0
0

I am trying to build a datatable based off a user defined function. I see a post where code is given on how to grab the column names dynamically: https://datatables.net/forums/discussion/comment/142403#Comment_142403

However, I am having trouble getting the data into the correct format. If you look at my commented out lines, there are several techniques I have tried (and you can probably tell by what I tried that I am very new to this :( )

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http;
using DataTables;
using Billing.Models;
using Newtonsoft.Json;

namespace Billing.Controllers
{
    public class ToGenerateController : ApiController
    {
        [Route("api/ToGenerate")]
        [HttpGet]
        [HttpPost]
        public IHttpActionResult toGenerate()
        {
            var request = HttpContext.Current.Request;
            var settings = Properties.Settings.Default;
            var AsOfCookie = request.Cookies["AsOfDate"].Value;
            string query = "select * from udf_FundOrgFTE_AdjustedFTEPercentages ('" + AsOfCookie + "')";
            string connectionString = settings.DbConnection;

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(query, conn);

                conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                var dt = new System.Data.DataTable();
                dt.Load(reader);
                object[] result = new object[dt.Rows.Count + 1];

                for (int i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    result[i] = dt.Rows[i].ItemArray;
                }

                reader.Close();
                return Json( result);
                //string strArray = "{ 'draw':null,'data':[" + result.ToString() + "]}" ;
                //return Json( strArray );
                //var json = JsonConvert.SerializeObject(result);
                
                //return Json(json);
                //return Json("{ 'draw':null,'data':[" + result + "]}");
            }
        }

    }
}

EDITOR will not save, results in NULL id.

$
0
0

Evaluate Datatables and Editor and been having a heck of a time. I generated a basic 'proof of concept' datatable with editor (PHP) to evaluate. And while initially appeared to work, I found out it does not save edit/updates.

Each time I click update I get:
An SQL error occurred: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: ""

Using Postgres database.
Primary key is "id" (lowercase). Though I am explicitly stating that in the editor.
Popup window Editor (not bubble or inline)

Code is as follows. This was generated using Generator. Since then, and as an attempt to figure it out, the only change I made was to add in isSrc and Field:inst('id'), which based on other readings shouldnt be needed since Iam using 'id' as the primary key.

(sorry, cant provide a link to an example)

PHP

<?php

/*
 * Editor server script for DB table transaction
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
$out = Editor::inst( $db, 'transaction', 'id' )
        ->fields(
                Field::inst( 'id' )->set(false),
                Field::inst( 'transaction_date' )
                        ->validator( Validate::dateFormat( 'Y-m-d' ) )
                        ->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
                        ->setFormatter( Format::dateFormatToSql( 'Y-m-d' ) ),
                Field::inst( 'chq_num' ),
                Field::inst( 'payee_orig' ),
                Field::inst( 'payee' ),
                Field::inst( 'memo_orig' ),
                Field::inst( 'memo' ),
                Field::inst( 'category_id' ),
                Field::inst( 'tax_category_id' ),
                Field::inst( 'transaction_amount' ),
                Field::inst( 'balance' )
        )
        ->process( $_POST )
        ->json();

JS

/*
 * Editor client script for DB table transaction
 * Created by http://editor.datatables.net/generator
 */

(function($){

$(document).ready(function() {
        var editor = new $.fn.dataTable.Editor( {
                ajax: 'php/table.transaction.php',
                table: '#transaction',
                idSrc: 'id',
                fields: [
                        {
                                "label": "Date:",
                                "name": "transaction_date",
                                "type": "datetime",
                                "format": "YYYY-MM-DD"
                        },
                        {
                                "label": "Chq:",
                                "name": "chq_num"
                        },
                        {
                                "label": "Payee:",
                                "name": "payee_orig"
                        },
                        {
                                "label": "Memo:",
                                "name": "memo_orig"                                                                                                                                                                                                                  
                        },
                        {
                                "label": "Category:",
                                "name": "category_id"
                        },
                        {
                                "label": "Accounting:",
                                "name": "tax_category_id"
                        },
                        {
                                "label": "Amount:",
                                "name": "transaction_amount"
                        },
                        {
                                "label": "Balance:",
                                "name": "balance"
                        }
                ]
        } );

       } );

        var table = $('#transaction').DataTable( {
                dom: 'Bfrtip',
                ajax: 'php/table.transaction.php',
                columns: [
                        {
                                "data": "transaction_date"
                        },
                        {
                                "data": "chq_num"
                        },
                        {
                                "data": "payee_orig"                                                                                                                                                                                                                 
                        },
                        {
                                "data": "memo_orig"
                        },
                        {
                                "data": "category_id"
                        },
                        {
                                "data": "tax_category_id"
                        },
                        {
                                "data": "transaction_amount"
                        },
                        {
                                "data": "balance"
                        }
                ],
                select: true,
                lengthChange: false,
                buttons: [
                        { extend: 'create', editor: editor },
                        { extend: 'edit',   editor: editor },
                        { extend: 'remove', editor: editor }
                ]
        } );
} );

}(jQuery));
Viewing all 81697 articles
Browse latest View live


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