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

preGet not working

$
0
0

I want to change the field value of pregroupdata.status before datatable read from database. I use preGet event to implement. But it is not work.

There is my code.

<?php
header("Conten-Type:text/html;charset=utf-8");
/*
 * Example PHP implementation used for the index.html example
 */

// DataTables PHP library
include( "../../php/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;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'pregroupdata' )
    ->fields(
        Field::inst( 'pregroupdata.appdate' ),
        Field::inst( 'pregroupdata.status' )->set(Field::SET_BOTH),
        Field::inst( 'pregroupdata.setupdate' ),
        Field::inst( 'pregroupdata.pastoralid' )->validator ( 'Validate::notEmpty' )
                                   ->options ( Options::inst()
                                                ->table( 'pastoral' )
                                                ->value( 'id' )
                                                ->label( 'name' )
                                             ),
        Field::inst( 'pname.name' ),
        Field::inst( 'pregroupdata.zoneid' )->validator ( 'Validate::notEmpty' )
                               ->options ( Options::inst()
                                                ->table( 'zonedata' )
                                                ->value( 'id' )
                                                ->label( 'name' )
                                             ),
        Field::inst( 'zname.name' ),
        Field::inst( 'pregroupdata.leaderid' )->validator ( 'Validate::notEmpty' )
                                 ->options ( Options::inst()
                                                ->table( 'leader' )
                                                ->value( 'id' )
                                                ->label( 'name' )
                                             ),
        Field::inst( 'lname.name' ),
        Field::inst( 'lname.phone' ),
        Field::inst( 'lname.cellphone' ),
        Field::inst( 'lname.identity' ),
        Field::inst( 'pregroupdata.groupname' ),
        Field::inst( 'pregroupdata.gdate' ),
        Field::inst( 'pregroupdata.gtime' ),
        Field::inst( 'pregroupdata.gplace' ),
        Field::inst( 'pregroupdata.property' ),
        Field::inst( 'zlname.name'),
        Field::inst( 'zlname.phone'),
        Field::inst( 'zlname.cellphone'),
        Field::inst( 'zlname.identity' )
    )
    ->leftJoin('leader as lname', 'pregroupdata.leaderid','=','lname.id')
    ->leftJoin('zonedata as zname', 'pregroupdata.zoneid','=','zname.id')
    ->leftJoin('pastoral as pname', 'pregroupdata.pastoralid','=','pname.id')
    ->leftJoin('leader as zlname', 'zlname.id','=','zname.leaderid')
    ->on('preGet', function($editor, $id){
        $editor
            ->field('pregroupdata.status')
            ->setValue('test');
    })
    ->process( $_POST )
    ->json();

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


column.search() is not filtering my table

$
0
0

Can you please check what did I missed in my datatable. I've created a simple search but it's not filtering.

<input type="text" id="txtserial" name="txtSerial" class="form-control" />

Here's my javascript:

       var dtmyJob = $('#myJob').DataTable({
            "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            iDisplayLength: -1,
            sScrollY: "40vh",
            bScrollInfinite: true, //this property disables pagination
            "scrollCollapse": true,
            "paging": false,
            "bInfo": false,
            "bFilter": false,
            "bSort": false
        });

        $("#txtserial").on('keyup', function () {
            dtmyJob.columns(2).search(this.value).draw();
            alert(dtmyJob);
        });

sort string that has number with -

$
0
0

Hi I am new to datatable and I want to sort a column which has type as String that has number on it. Its sorting as String.

$(document).ready(function() {
$('#dashboard').DataTable({
"order": [[ 0, "desc" ]],
"lengthMenu" : [ [ 25, 50, 75, -1 ], [ 25, 50, 75, "All" ] ],
"pageLength" : 200,
"aoColumns": [ //When i changed the column type to num it sorts in beginning and after that-
{ "sType": "num" }, // -it does not sort.
null,
null,
null,
null,
null,
null,
null
]
});
});

Sample for my sorted column
AR-99
AR-983
AR-982
AR-981
AR-980
AR-98
AR-979
AR-978
AR-977
AR-976
AR-975
IR-99
IR-983
IR-982
IR-981
IR-980
IR-98
IR-979
IR-978
IR-977
IR-976
IR-975
....
....

I want the result as:
AR-983
AR-982
AR-981
AR-980
AR-979
AR-978
AR-977
AR-976
AR-975
...
...
IR-983
IR-982
IR-981
IR-980
IR-979
IR-978
IR-977
IR-976
IR-975
IR-974

Can any one help me with this please?

Requested unknown parameter '0' for row 0, column 0.

$
0
0

I'm using DataTables and Editor and am getting this dialog popup:

"DataTables warning: table id=ImmigrationNotes - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4"

And when I click to make it go away, the table shows up with the correct number of records yet, there is no text in any of the fields.

No colspan or rowspan in the tbody. The number of columns are equal in the header and table body and are what's in the HTML.

What more can cause the warning? and Why does the correct number of rows show up but no text in any cell?

How Can I Get Data From Selected Row?

$
0
0

Hi,
I am new to DataTables and I am trying to discover the details of that issue.I have a table that ı am getting the data's of the tables rows from database.I can list the datas in row with using DataTables but I want to get datas from selected row when i click on the row and use that datas for editing,deleting,etc.

I have added my code snippet below my message.How can i do that?Can you help me please?

MY CODE

<html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
<title>AdminLogin</title>
<!-- Bootstrap -->
<link href="Content/bootstrap.min.css" rel="stylesheet"/>
<link href="Content/dataTables.bootstrap.min.css" rel="stylesheet"/>
<link href="Content/jquery.dataTables.min.css" rel="stylesheet" />
<link href="Content/select.dataTables.min.css" rel="stylesheet" />
 </head>
<body>
   <p><br/></p>
   <form id="form1" runat="server">
 <div class="container">
<div class="jumbotron">
       <h5>Hello  <asp:Label ID="lblUser" runat="server" ForeColor="Red"/> </h5>
       <h5><asp:LinkButton ID="btnLogOut" runat="server" ForeColor="Red" CssClass="pull-right" OnClick="btnLogOut_Click"
   Font-Underline="True">Log Out</asp:LinkButton> </h5>
    <h1>Kullanıcılar</h1>
    </div>
   <h1>User List</h1>
 <asp:Repeater ID="rptUsers" runat="server">
    <HeaderTemplate>
  <table class="table table-striped table-bordered table-hover" id="UserList">
  <thead>
  <tr>
  <th>User Name</th>
  <th>IsAdmin</th>
  </tr>
  </thead>
   <tbody>
  </HeaderTemplate>
   <ItemTemplate>
        <tr>
            <td>
                <asp:Label ID="lblUserName" runat="server" Text='<%# Eval("UserName~~~~") %>' />
            </td>
             <td>
                <asp:Label ID="lblAdmin" runat="server" Text='<%# Eval("IsAdmin") %>' />
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </tbody> </table>
    </FooterTemplate>
   </asp:Repeater>
    </div>
     <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
     <script src="scripts/jquery-1.12.4.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="scripts/bootstrap.min.js"></script>
   <script src="scripts/jquery.dataTables.min.js"></script>
    <script src="scripts/dataTables.bootstrap.min.js"></script>
     <script src="scripts/dataTables.select.min.js"></script>
    <script>

      $(document).ready(function () {
          $('#UserList').DataTable({
            "aLengthMenu": [[4, 8, 12, -1], [4, 8, 12, "All"]],
            "iDisplayLength": 4,
            select: {
                style: 'single'
            }
        });
     });
    </script>
       </form>
    </body>
 </html>

Creating custom search on jquery datatables

$
0
0

I need help with customizing jquery datatables search. I need to make main search to work for individual columns. In fact I have to implement this logic (https://datatables.net/examples/api/multi_filter.html) in my main search input, so it have search logic like these individual footer inputs.

I have this code right now but its still not working as expected. Please help...

var table = $('#editable-usage').DataTable();
table.columns().every(function() {
    var that = this;
    $('#editable-usage_filter input').on('keyup change', function() {
        if (that.search() == this.value) {
            that.search(this.value).draw();
        }
    });
});

Editable fields changes based on users selection

$
0
0

Is it possible to implement editing where editable fields are based on some selection? For example, if I have dropdownlist of Vehicles where I have: Car, Motorcycle, Truck. And based on that selection I want to show different fields for each vehicle. For example if user selects car I would like to show "number of doors", "model of car"... and other car specific details. And if user selects motorcycle I want to show some motorcycle specific questions and so on...

Prevent row deselection

$
0
0

Hello.
I'm using DataTables with Select extension.
select: {style: "single"}
So user selects a row by clicking on it.
I don't want the row to be deselected when user clicks on it again. Just do nothing.
Any informaton on how to stop deselect event?

"datatables.net": "^1.10.16",
"datatables.net-bs": "^2.1.1",
"datatables.net-select-bs": "^1.2.3",

How to export custom CSV file ?

$
0
0

My table cell is a <input> element ,and some operation button .In this condition , how to export custom data to csv file ? I want to use the buttons extension to implement it.

Custom server-side DataTables processing: “typeof(Enumerable).GetMethod” is null

$
0
0

Hello everyone,
I have been struggling for days over an old (2011) piece of C# code I extracted from a DLL my boss wants me to edit.

The application queries a database with LINQ, server-side processes it and displays the data with a DataTable.
From what I gathered, the guy who wrote it had created an ASP.NET Web Forms Site in Visual Studio 2010, with .NET Framework 4.0.

He used the server-side parser from Zack Owens.
In the project I recreated in VS 2017, everything builds well, but at runtime, a bug comes from the little customizations he made to the DataTable parser: among them, the SelectProperties() function has been completely rewritten from this:

    private Expression<Func<T, List<string>>> SelectProperties
    {
        get
        {
            return value => _properties.Select
            (
                // empty string is the default property value
                prop => (prop.GetValue(value, new object[0]) ?? string.Empty).ToString()
            )
            .ToList();
        }
    }

to this:

    private Expression<Func<T, List<string>>> SelectProperties
    {
        get
        {
            var parameterExpression = Expression.Parameter(typeof(T), "value");

           // (Edited) The bug happens there: type_RD is null because GetMethod is not valid
            var type_RD = typeof(Enumerable).GetMethod(
                "ToList",
                new Type[] {
                    typeof(IEnumerable<string>)
                }
            );

            // The program crashes there (System.Null.Exception)
            var methodFromHandle = (MethodInfo)MethodBase.GetMethodFromHandle(
                type_RD
            .MethodHandle);

            var expressionArray = new Expression[1];

            var methodInfo = (MethodInfo)MethodBase.GetMethodFromHandle(
                typeof(Enumerable).GetMethod("Select", new Type[] {
                    typeof(IEnumerable<PropertyInfo>),
                    typeof(Func<PropertyInfo, string>)
                })
            .MethodHandle);

            var expressionArray1 = new Expression[] {
                Expression.Field(
                    Expression.Constant(
                        this,
                        typeof(DataTableParser<T>)
                    ),
                    FieldInfo.GetFieldFromHandle(
                        typeof(DataTableParser<T>).GetField("_properties").FieldHandle,
                        typeof(DataTableParser<T>).TypeHandle
                    )
                ), null
            };

            var parameterExpression1 = Expression.Parameter(
                typeof(PropertyInfo),
                "prop"
            );

            var methodFromHandle1 = (MethodInfo)MethodBase.GetMethodFromHandle(
                typeof(PropertyInfo).GetMethod(
                    "GetValue",
                    new Type[] {
                        typeof(object),
                        typeof(object[])
                    }
                )
            .MethodHandle);

            var expressionArray2 = new Expression[] {
                Expression.Convert(
                    parameterExpression,
                    typeof(object)
                ),
                Expression.NewArrayInit(
                    typeof(object),
                    new Expression[0]
                )
            };

            var methodCallExpression = Expression.Call(
                Expression.Coalesce(
                    Expression.Call(
                        parameterExpression1,
                        methodFromHandle1,
                        expressionArray2
                    ),
                    Expression.Field(
                        null,
                        FieldInfo.GetFieldFromHandle(
                            typeof(string).GetField("Empty").FieldHandle
                        )
                    )
                ),
                (MethodInfo)MethodBase.GetMethodFromHandle(
                    typeof(object).GetMethod("ToString").MethodHandle
                ),
                new Expression[0]
            );

            expressionArray1[1] = Expression.Lambda<Func<PropertyInfo, string>>(
                methodCallExpression,
                parameterExpression1
            );
            expressionArray[0] = Expression.Call(
                null,
                methodInfo,
                expressionArray1
            );

            // Return Lambda
            return Expression.Lambda<Func<T, List<string>>>(
                Expression.Call(
                    null,
                    methodFromHandle,
                    expressionArray
                ),
                parameterExpression
            );
        }
    }

My questions:

  • How to make the SelectProperties function work?
  • What exactly is its purpose? I didn't get any of the "MethodHandle" bits ...

The only hint I have is that, when I use the original SelectProperties code, the data are in the wrong columns and the sorting causes errors 500 with some of the columns.
Here is the other customized function of this custom DataTable.cs parser:

        public FormatedList<T> Parse()
        {
        var list = new FormatedList();
        list.Import(_properties.Select(x => x.Name).ToArray());

        list.sEcho = int.Parse(_httpRequest[ECHO]);

        list.iTotalRecords = _queriable.Count();

        ApplySort();

        int skip = 0, take = 10;
        int.TryParse(_httpRequest[DISPLAY_START], out skip);
        int.TryParse(_httpRequest[DISPLAY_LENGTH], out take);

        /* (Edited)
        list.aaData = _queriable.Where(ApplyGenericSearch)
                                .Where(IndividualPropertySearch)
                                .Skip(skip)
                                .Take(take)
                                .Select(SelectProperties)
                                .ToList();

        list.iTotalDisplayRecords = list.aaData.Count;
        */
        list.aaData = _queriable.Where(ApplyGenericSearch)
                                .Where(IndividualPropertySearch)
                                .Skip(skip)
                                .Take(take)
                                .ToList()
                                .AsQueryable()
                                .Select(SelectProperties)
                                .ToList();

        list.iTotalDisplayRecords = list.iTotalRecords;

        return list;
        }

I am a beginner at C#, .NET, Linq etc., though I know quite a few other languages.
Setup: Windows 7 64, Visual Studio 2017.

Thank you for your help!

Standalone editor - without datatables but with database read/write

$
0
0

Is it possible to have functionality (standalone editor) like this:
* I can generate any html page (i.e. google maps), and object identified by table row_id
* I can open editor main form using api, sending row_id (editor.edit(row_id) )
* however, form is not initialised (because datatable is missing - standalone mode)
* when I put values in the form and save, it's ok, values are saved in the correct record on server

Can I initialize form somehow smartly ? I can see only two options now:
* I can write form values into html elements during the page generation
* I can make some ajax call (preferably same one as for datatables init) and fill the values via editor.set calls

I really would like to open same editor form as for datatables mode (which can be complex, with select2, upload forms)
Is it possible ?

Pagination not working in salesforce lightning component.

$
0
0

Hi,
I am using data tables in Salesforce lightning component. In the component i am try to do pagination and getting few of issue so i need help.
1. On page load it is showing 10 records, so when i change record count to 25 it is showing 25 records which is right but when i move record count to 10 then it is showing 25 record.
2. After page load when i click on next button it is not hide previous records and showing next 10 record.

THIS IS THE CODE

var table = $('#msgPreview')
.on( 'page.dt', function () {
console.log('================= before pagination');
})
.on( 'order.dt', function () {
console.log('================= before sorting');
})
.DataTable({
"order": [
[1, 'asc']
],
"initComplete": function(settings, json) {
console.log('================= initComplete');
var sortNameIcon = component.find("sortNameIcon");
sortNameIcon.set("v.iconName", 'utility:arrowup');
//var prePagination = component.get("c.preHandlePagination");
//$A.enqueueAction(prePagination);
var spinner = component.find('spinner');
$A.util.addClass(spinner, 'slds-hide');
},
"fnDrawCallback": function(settings, json) {
console.log('================= fnDrawCallback');
//var action = component.get('c.preHandlePagination');
//$A.enqueueAction(action);
},
paging: true,
searching: false,
ordering: true,
info: false,
retrieve: false,

        rowReorder: {
            selector: 'tr',
        },
        columnDefs: [{
            targets: 0,
            visible: true
        }]
    });

Or is there any method which is calling after sorting method then that is also very helpful.

Please Help! i got stuck on this issue form very long time.

Is that possible to use datatable in Salesforce Lightning? Expert advice please

$
0
0

I have already using datatable in my visualforce page in Salesforce classic. Is that possible to use datatable in Salesforce Lightning? Expert advice please

How to set? ScrollX: true, width = 100%

Nested editors - scrolling question on secondary editor

$
0
0

Hi everyone,

I'm using the 'Bootstrap' display controller for all my table.

For a specific table, I needed to have a nested editor (a pop up with details) and since using Bootstrap display for my secondary editor looks compromised (according to the posts I read
due to bootstrap limitation with multiple modals) I used the [jQueryUI display controller (https://editor.datatables.net/reference/display/jqueryui "jQueryUI display controller").

After some tuning (z-index etc...) my secondary window shows up with a limitation however on scolling. Infact my secondary editor is higher than the modal original editor and therefore the bottom part of it is 'under my screen' with no way to reach it with scrolling (blcked, probably due to my 'parent bootstrap modal' editor.

Do you have in mind any tricks which would enable scrolling in my secondary editor which is nested in a bootstrap modal?

Many thanks!

Sébastien

PS: any elegant / inelegant suggestion is welcomed ! If anyone has a solution to use full bootstrap solution in this case he could count on all my admiration !


stateSave not saving paging position

$
0
0

Hi guys,

I have the following

 $("#dtCustomers").dataTable().fnDestroy();
        $('#dtCustomers').empty();
        tableCustomers = $('#dtCustomers').DataTable( {

        ajax: {
        url : "http://www.xxx.com/xxx.php",
        type: 'POST'

        },
        //serverSide : true,
        customerData : data,
        scrollY: "300px",
        scrollCollapse: true,
        lengthChange: false,
        pagingType: "simple",
        stateSave: true,
        stateSaveCallback: function(settings,data) {
          localStorage.setItem( 'DataTables_' + settings.sInstance, JSON.stringify(data) )
        },
        stateLoadCallback: function(settings) {
          return JSON.parse( localStorage.getItem( 'DataTables_' + settings.sInstance ) )
        },
        paging: true,
        info: false,
        select: true,
        ordering: true,
        order: [[0, 'desc']],
        dom: "Bfrtip",
        autoWidth : true,
        responsive: true,
        select: true,

On the customer table.
I page down and expand a row
In another instance I update some data in the row
I then hit refresh button which reloads the ajax
The datatable is set to the first record.
If I page down I see the row in its open state with the new data.

So the paging position doesn't seem to be working.

I see in the Local Storage the following

DataTables_dtCustomers

{"time":1513858618095,"start":0,"length":10,"order":[[0,"desc"]],"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true},"columns":[{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}}]}

Am I missing an option or something here ?

Cheers

Steve Warby

Responsive mode auto close and open other views.

$
0
0

Is it possible to have a max of 1 row expanded.

ie row 1 is expanded.
When expand row2 , row closes.

Cheers

Steve Warby

Keeping an entire rowSource group together

$
0
0

Is it possible to programmatically keep all rows within a rowSource grouping together within the same page (thus possibly overriding the pre-set page length)?

For example, if I have a dataset to display using DataTables that has a total of 100 records, and I set my default page length to 10. Assume that one of the groupings within that 100 records has 25 records, while other groupings have 4 or 5 or 10 records.

Is it possible to visually keep all 25 records of the large rowSource grouping together on a single display page? The issue becomes that if I want to use the startRender or end Render function within rowSource, that if a grouping of say 25 records happens to fall so that some portion of the records is on one page, and the remainder is on the next page, then the startRender (or endRender) will execute twice, once for each subset of the records on its page. The end result is that any calculations displayed as the result of the renderer being executed once for each subset, is that the displayed calculations aren't correct for the entire grouping, but only for each subset of the grouping.

I hope this makes sense. I'll try to build a fiddle later today that illustrates what I'm asking.

Multi Column sort and Custom Type fails to sort second column

$
0
0

I've come across an issue where datatables is failing to sort second column in a order when using a custom type

see: http://live.datatables.net/dirajulu/1/edit

When you press the "button" it shows the icon to indicate both columns are being sorted but the console output is not showing for the second columns sorting.

Repeated pressing it appears to be causing a asc/desc toggle to occur on the 2nd column?

How to filter a checkbox column by checkbox state?

$
0
0

The user wants to have filter options for each column. The table has multiple columns where only a checkbox exists in the cell.

When the user chooses "Selected" option here:

he wants the table to only show the rows which have checked checkbox in that column. He also wants to be able to apply multiple filters together.

So far it's working as requested but there is this issue: when the user changes the state of the checkboxes, DataTables appears to be unaware of the change and continues to filter as the checkbox was never modified. Reloading the page fixes this but I need to somehow inform DataTables that data has changed, so that the filters would filter correctly even when the data has changed but the page has not yet been reloaded.

The code:

This is how I'm trying to tell DataTables that DOM has changed (but that's not working):

Viewing all 81798 articles
Browse latest View live


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