Quantcast
Channel: Free community support — DataTables forums
Viewing all 35368 articles
Browse latest View live

SharePoint People/Group Picker - returning properties

$
0
0

without datatables, working code looks like this:

var requestUri = webAbsUrl + "/_api/web/Lists/getByTitle('Directory')/Items?$\
filter=JobTitle eq 'Deputy Director'&$\
select=Phone, JobTitle, Name/EMail, Name/FirstName, Name/LastName, Photo&$\
expand=Name/Id";

            var ajaxOrg = $.ajax({
                url: requestUri,
                async: false,  //pass value outside of ajax
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: function (data) {
                    if (data.d != undefined) {
                        $.each(data.d.results, function (index, item) {
                            myFirstName = item.Name.FirstName;
                            myLastName = item.Name.LastName;
                            myEmail = item.Name.EMail;
                            myPhone = data.d.results[0].Phone;
                            myJobTitle = data.d.results[0].JobTitle;
                            myPhotoURL = data.d.results[0].Photo.Url;   
                            i++;
                        });
                    }
                },
                error: function (data) { alert("Failed to load your profile."); }
            });

With datatables, I can't figure out how to pull the properties from the Name column which is of People/Group field type. I want to pull the email, first, and last names from the NAME column.

Using below returns [object Object] in column rather than displaying the FirstName
"aoColumns": [
{ "mData": "Name",
"fnRender":function(mData) {
if(obj.aData.Name.results != undefined) {
$.each(obj.aData.Name.results, function(index,item) {
return item.FirstName;
});
}
}
},
{ "mData": "Phone"}
],
});


How to disable the transfer to a new line in KeyTable?

$
0
0

Hi. I have use a KeyTable extension. When focused key reaches the end of the line the focus goes to a new line. Can I make the focus return to the first cell of the same line ???

Hi All! I am new to datatables. I am using this to display results from ajax call.

$
0
0

On a single page, I have user form and the result section. User fills the details and submit. On this, datatable is displayed. This works perfectly fine. But when user updates anything on the form and submits it, I am trying to destroy datatable and recreate it. Doing this, i am getting the error - clientWidth of undefined. Below is the code -

function CBResults(response){
    var dataArray = response.data;
    
    
    
    if ($.fn.DataTable.isDataTable("#thetable")) {
        $('#thetable').dataTable();
        $('#thetable').DataTable().clear().destroy();
        
        
    }
    var html = '<tbody>';
    for(var i = 0; i < dataArray.length; i++)
        html += '<tr><td></td></tr>';  // code to populate columns of the table
    
    html += '</tbody>';
    
    
        $('#thetable thead').first().after(html);

        $('#thetable').DataTable( {
            retrieve: true,          
            dom: 'Blfrtip',
            scrollY: "300px",
            responsive: true,
            scrollX:        true,
            scrollCollapse: true,
            columnDefs: [ {
                targets: [4,5,6,7,8,9,10,11],
                render: $.fn.dataTable.render.ellipsis(10)
            } ], 
            buttons: [
                'colvis','copy', 'csv', 'excel', 'pdf'  
            ],
            fixedColumns:   {
                leftColumns: 2
            },
            
             "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
        } );
}

Let me know what I am doing wrong and how can I correct it? Appreciate quick reply on this.

hide limit dropdown

$
0
0

Hi,
I have just publish 'copy', 'csv', 'excel', 'pdf', 'print' button but after the publish button it hides the list quantity dropdown where i select 10/20/50/100.
kindly help me how to get back that dropdown.
Thanks
Harun

Automatic change of one field after changing another

$
0
0

Hello. Can I make it so that when the value in one of the cells changes, the function of updating the value in another cell automatically works? For example, there are fields "Number 1", "Number 2" and "Sum". After changing the fields "Digit 1" or "Digit 2" the function of the amount recalculation should work and further the received value should be updated in the "Amount" cell. All this should be preserved in the database, and then return the value to the cell.

Additional last row to display accumulated data.

$
0
0

Hi, I would like to add a row to accumulate the records and display the total amount as the last row. I have been searching for similar examples but I have not found one yet, does anyone knows how to solve this?

I have included an example table that I would like to create, to accumulate all records above in an additional row at the bottom to display the total.

Is it possible to achieve a series of nested tables like this with Datatables?

$
0
0

See attached image. I'm trying to achieve a technique where the rows example and reveal higher level data. Could this be done with rowspans or the grouping functions in datatables? Any pointers are appreciated.

Bootstrap 4 and datatables dont work seem to work together

$
0
0

Hello everyone,

I was wondering if people could check out why my datatables isn't working when I'm using bootstrap 4.

Before I never used bootstrap , now I started to use it and combine it with datatables my datatables doesn't work anymore.

Maybe I have the wrong CDN's , or something else

Could you please check it ou my code here? https://paste.ofcode.org/x7vNXtKwdyySEAR9sTD6WX

Regards

sjaakie


How to add "date" from column to title

$
0
0

I have a column dates in table and when i search for a certain date it should be able to print only that date with the title of that date. Table for that date is printed automatically and works beautiful, but i cannot put that date into the title. Any help?

How to solve the problem that the child form and parent form are not aligned

$
0
0

The inner and outer tables have the same structure, and the inner layer has no header. After embedding, the sub-table is shifted to the right as a whole.

Asp.net Core Editor example

$
0
0

First of all, a bit of background - recently started my first asp.net core project, or it would more precise to say first dev project in like 10 years, so yeah, currently rate myself a newb in development.

So when I got the multi-tenancy, authentication, authorization done, I started to look for UI elements for my project, came across datatables, and was pretty sure that I would love to include this UI element in my project. Editing data grids is a must for me, so it was disappointing to find out that there is no libraries for asp.net core for Editor server-side. Although I haven't yet bought it, I decided to try to implement the server side myself. Long story short, 2 days later I have editable table, and I am willing to share my solution, as it could help someone else or me (by someone improving upon it). So here we go.

  1. Models
    public class ProjectType

    {
        [Required]
        public int Id { get; set; }
        [Required]
        public string ProjType { get; set; }


    }
 public class ProjectTypeDTable : ProjectType
    {
        public string DT_RowId { get; set; }
    }
  1. Editor and datatable initialization
    <script type="text/javascript">
        

        $(document).ready(function () {

            var editor = new $.fn.dataTable.Editor({
                ajax: {
                    url: '/api/dtprojecttype',
                    data: function (d) {
                        return JSON.stringify(d);
                    },
                    contentType: "application/json"
                },
                table: '.projecttypes-table',
                idSrc: 'id',

                fields: [
                    {
                        name: "projType",
                        label: "Project Type: "
                    }
                ],
            });

          var generateProjectTypesTable = 
                $('.projecttypes-table').DataTable({
                    columns: [
                        {
                            data: "id",
                            searchable: false,
                        },
                        
                        { data : "projType" }

                    ],
                    ordering: true,
                    paging : true,
                    pagingType : 'full_numbers',
                    pageLength : "25",
                    select : true,
                    dom: '<"html5buttons"B>lTfgitp',
                    buttons : [
                        { extend: 'create', editor: editor },
                        { extend: 'edit', editor: editor },
                        { extend: 'remove', editor: editor },
                        { extend: 'copy' }
                    ]

                });         

            //$('.projecttypes-table').on('click', 'tbody td', function () {
            //    editor.inline(this);
            //});

        });

    </script>

  1. Server side api action
 public async Task<IActionResult> Post([FromBody]JObject request)
        {
            //split incomming JSON object into action and data JTokens
            var action = request.GetValue("action").ToString();
            var data = request.GetValue("data");

            IList<ProjectTypeDTable> testchangedobjects = new List<ProjectTypeDTable> { };
            test

            //define new list for changed objects
            IList<ProjectTypeDTable> changedobjects = new List<ProjectTypeDTable> { };

            //parse json to class objects
            changedobjects = changedobjects.DTableEditParser(request, "Id", "Int");

            //create empty List for response objects
            IList<ProjectTypeDTable> responseobjects = new List<ProjectTypeDTable> { };


            if (action == "create")
            {
                foreach (var x in changedobjects)
                {
                    var changed = new ProjectType
                    {
                        ProjType = x.ProjType
                    };

                    changed = await _tenantdbrepo.AddProjectTypeAsync(changed);

                    responseobjects.Add(new ProjectTypeDTable { Id = changed.Id, ProjType = changed.ProjType, DT_RowId = "row_" + changed.Id.ToString() });
                };
            }
            else if (action == "edit")
            {
                foreach (var x in changedobjects)
                {
                    var changed = new ProjectType
                    {
                        Id = x.Id,
                        ProjType = x.ProjType
                    };
                        
                      changed =  await _tenantdbrepo.UpdateProjectTypeAsync(changed);
                    responseobjects.Add(new ProjectTypeDTable { Id = changed.Id, ProjType = changed.ProjType, DT_RowId = x.DT_RowId ?? "row_"+changed.Id });
                };
            }
            else if (action == "remove")
            {
                foreach (var x in changedobjects)
                {
                    var changed = new ProjectType
                    {
                        Id = x.Id,
                        ProjType = x.ProjType
                    };
                    await _tenantdbrepo.RemoveProjectTypeAsync(changed);
                };
            };

            
            if (responseobjects.Any())
            {
                dynamic response = new
                {
                    data = responseobjects
                };
                return Json(response);
            }
            else
            {
                dynamic response = new { };
                return Json(response);
            };

        }
  1. My extension that parses the json to objects
public static class DatatablesEdit
    {

   
    public static IList<T> DTableEditParser<T>(this IList<T> source,  JObject json, string id, string idtype)
        {
            //split incomming JSON object into action and data JTokens
            var action = json.GetValue("action").ToString();
            var data = json.GetValue("data");

            IList<T> changedobjects = new List<T> { };

            foreach (JProperty x in data)
            {
                //initialize empty object of class
                T changedobject = (T)Activator.CreateInstance(typeof(T));
                

                //set object's ID property to JSON objects Name
                if (idtype =="int")
                {
                    changedobject.GetType().GetProperty(id).SetValue(changedobject, Int32.Parse(x.Name.ToString()));
                } else if (idtype == "string")
                {
                    changedobject.GetType().GetProperty(id).SetValue(changedobject, x.Name.ToString());
                }
                
                

                //loop through each of JSON object sub properties, change the property name from camel case to pascal case and map to object's properties
                foreach (JProperty y in x.Value)
                {
                    string propertyname = char.ToUpper(y.Name[0]) + y.Name.Substring(1);

                    if (changedobject.GetType().GetProperty(propertyname).PropertyType.Name == "String")
                    {
                        changedobject.GetType().GetProperty(propertyname).SetValue(changedobject, y.Value.ToString());
                    }
                    else if (changedobject.GetType().GetProperty(propertyname).PropertyType.Name == "Integer")
                    {
                        changedobject.GetType().GetProperty(propertyname).SetValue(changedobject, Int32.Parse(y.Value.ToString()));
                    }
                }
                //add object to changed objects List
                changedobjects.Add(changedobject);
            }


            return changedobjects;
        }
       
    }

I am sure that the code is far from optimal, but I am pretty proud of myself to get this working. Any improvements appreciated.

How to add "aria-label" attribute to the button

$
0
0

Allan,

I have tried to add the "aria-label" to those export buttons(see below) but those buttons disappear . Any suggestion on how to add the aria-label attribute to the button? Thanks.

attr: {
title: 'export to excel',
aria-label: 'export'
}
}

Thanks.

Do not show table when there is no data

$
0
0

A developer has used this library to integrate into our app. But has forgotten to manage the case where the data set is 0 sized. How is this case handled ?

[Bug] PDF Export Button Uncaught Malformed table row, a cell is undefined

$
0
0

https://github.com/DataTables/DataTables/issues/1044

Hi,

There is a bug on HTML 5 PDF export button is pressed when there is no data available on tbody. Console.log will print
Uncaught Malformed table row, a cell is undefined.

I have created a jsfiddle to reproduce the bug, the original source code is clone from https://datatables.net/extensions/buttons/examples/html5/simple.html

https://jsfiddle.net/1o9vcv3r/2/

Expected behavior - The PDF export button should work properly likes other export buttons do even though no data is available.

Thank for your time

Best Regards

Column Edit for only single select not for multi select

$
0
0



My question is client code column should me editatable only for single row edit and it should not edit or resd only or hide for multi row edit how to make it


RowReorder - dataTable is not displayed properly

$
0
0

Hello all,

I have a problem with the RowReorder of DataTable, I expose you the stack that I use:

  • Symfony 3.4
  • Webpack Encore
  • Boostrap 4

In my JS file, to import after adding "datatables.net-rowreorder-bs4" via yarn, I make a "require ('datatables.net-rowreorder') ();".

It works and I can use rowreorder, the problem is that it skipped my CSS Bootstrap 4 and the rest of the dataTable is not displayed properly.

Ideas ?

Merci.

How to send custom header on next of ajax in datatable?

$
0
0

I am using datatables and I want to send some custom header as due to some server side requirement. Can you guys please tell me how can I send custom header on next and previous using this jquery datatables.

Where also serverSide: true

Al cambiar resoluciones en otro tab me falla la tabla

$
0
0

Tengo una tabla en un tab con varios div ocultos cuando estoy en otro tab, redimensiono la ventana y vuelvo a la del datatable y se me ve mal como la imagen que adjunto que puedo hacer para arreglar esto.

colvisRestore ( A script on this page may be busy, or it may have stopped responding )

$
0
0

hi allen

i had implemented colvis **: https://datatables.net/extensions/fixedcolumns/examples/styling/colvis.html where the table has 45columns.
then implemented **colvisRestore

code :
{
extend:'colvisRestore',
text:'Default View'
}

but when user clicks on Default View button works fine but the browser hangs goes to unresposive state or get the popup saying (A script on this page may be busy, or it may have stopped responding ....) .Please find attachment for the screen shot.

Note:
this bug occurs in Mozilla browser but not in chrome.

Is it possible to data-table API use for div binding

$
0
0

Is it possible to data-table API use for div binding like the table? If yes, can you send me an example or hint?

Viewing all 35368 articles
Browse latest View live