Editor REST Example SharePoint 2010

Editor REST Example SharePoint 2010

Dwayne JarmanDwayne Jarman Posts: 7Questions: 2Answers: 0

Hi,

I'm trying to use the Editor to perform inline edits with SharePoint 2010. Weve used datatables for over 2 years and really like it and purchased the editor. Now, though, I'm not sure how to implement the editor. We really, at this time want to edit records.

I'm not even able to get the page to load the data to the table. Here is a copy of my code:

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: {
            edit: {
                type: 'PUT',
                url:  '../php/rest/edit.php?id=_id_'
            }
        },
        table: "#example6",
        fields: [ {
                label: "EmployeeDN:",
                name: "EmployeeDN"
            }
        ]
    } );
 
    $('#example6').DataTable( {
        dom: "Bfrtip",
        paging: false,
        searching: false,
        ajax: $.ajax({
            'url': thisbase + "/_vti_bin/ListData.svc/List?$select=Id,EmployeeDN",
            'headers': { 'Accept': 'application/json;odata=verbose' },
            type: "GET", 
            dataType: "json", 
            success: function (data) {
                
                var r = data.d.results;
                var revised = new Array();  
                            
                    for(i = 0; i< r.length; i++){    
                        
                        var count = i+1;
                        
                        var n = new Object();      
                        n.DT_RowId = "row_"+count,                                              
                        n.Id = r[i].Id;
                        n.EmployeeDN = r[i].EmployeeDN;
                        revised.push(n);
                    }

                //console.log(JSON.stringify(revised));
                return revised;
            }
            /*'dataSrc': function(data) {
                return data.value.map(function(item) {
                    return [
                        //item.EmployeeDN
                        
                        item.ID,
                        item.BusinessUnit,
                        item.Category,
                        item.Status,
                        new Date(item.DueDate),
                        item.AssignedTo.Title
                    ];
                });
            }*/
        }),
        columns: [
            { data: "EmployeeDN" },
        ],
        select: true,
        buttons: [
            { extend: "edit",   editor: editor }
        ]
    } );
});

I used the console to pull the data returned:

[{"DT_RowId":"row_1","Id":320,"EmployeeDN":"XXX"},{"DT_RowId":"row_2","Id":347,"TripPriority":null,"EmployeeDN":"YYY"}]

Not quite sure where to go from here.

Answers

  • allanallan Posts: 43,187Questions: 1Answers: 5,628 Site admin

    ajax: $.ajax({

    That isn't going to work. That will assign a jQuery XHR object to DataTables' ajax option, and while the Ajax call will be made, nothing will be done with it.

    Could you change the ajax option to be:

            ajax: {
                'url': thisbase + "/_vti_bin/ListData.svc/List?$select=Id,EmployeeDN",
                'headers': { 'Accept': 'application/json;odata=verbose' },
           }
    

    It will likely result in an error, but run the DataTables debugger over the table and let me know what the debug code is so I can see what is going on.

    Thanks,
    Allan

  • kungfulukungfulu Posts: 1Questions: 0Answers: 0

    I am also interested in this, trying to do the exact same thing. I just started the trial to see if this is a viable solution. We are trying to do inline edits on a SharePoint List. I tried the above code with the ajax suggestion. I don't get any type of error on the page but nothing loads. No error, no data.

  • allanallan Posts: 43,187Questions: 1Answers: 5,628 Site admin

    Can you run the debugger on your page so I can see how the table is configured please?

    Allan

  • Dwayne JarmanDwayne Jarman Posts: 7Questions: 2Answers: 0
    edited November 15

    I apologize for the delay. I didn't realize I had a response as I'm new to the community. I will check this tomorrow and let you know.

    I had to do a work around for this specific option because I only need to check one cell. I loaded dynamically a select field to every row, then looped through and compared a hidden field to the drop down. if the values were different I updated them. I think there must be a way to do it by high jacking the api submit function for the form controls but couldn't figure it out for some reason. I have lots of good crud examples based on good tutorials on the web for SharePoint 2010.

    I've used the datatables.net tool so much folks just love what we have been able to do. I really don't need to do this right now, but now I'm curious and want to figure it out.

Sign In or Register to comment.