Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete row ajax problem #229

Open
darkjackx opened this issue Sep 9, 2023 · 1 comment
Open

delete row ajax problem #229

darkjackx opened this issue Sep 9, 2023 · 1 comment

Comments

@darkjackx
Copy link

darkjackx commented Sep 9, 2023

// setup js
onDeleteRow: function(datatable, rowdata, success, error) {
    $.ajax({
        url: '/api/delete/product/1',
        type: 'POST',
        data: rowdata,
        success: function(response) {
            if (typeof success === 'function') {
                success(response);
            }
        },
        error: error
    });
}

//rowdata are working fine at onAddRow and onEditRow, but it has problem with onDeleteRow

////////// testing data
////// example 03 delete row
let s = {};
s.data = [
  {
      "id": 1,
      "name": "Tiger Nixon",
      "position": "System Architect"
  }
]
			s.data = jQuery.param( s.data, s.traditional );
      // s.data = 'Tiger%20Nixon='
////// customer data delete row
let s = {};
s.data = [
  {
    "p_id": "5",
    "p_brand": "mi",
    "p_name": "remei"
  }
]
			s.data = jQuery.param( s.data, s.traditional );
      // s.data = 'undefined='
@darkjackx
Copy link
Author

darkjackx commented Sep 9, 2023

temporary solution here


//setup.js
    onDeleteRow: function(datatable, rowdata, success, error) {
        $.ajax({
            url: '/api/delete/product/1',
            type: 'POST',
            data: getSelectedId(pTable, 'p_id'),
            success: function(response) {
                ////// Call the 'success' callback if it was provided
                if (typeof success === 'function') {
                    success(response);
                }
            },
            error: error
        });
    }
//// prepare data object support multi select
    function getSelectedId(table, idname) {
    let data = table.rows({ selected: true }).data().toArray();
    const objectData = {};

    data.forEach(item => {
        const idValue = item[idname]; // Use square brackets to access the property dynamically
        objectData[idValue] = "del";
    });
    console.log(objectData);
    return objectData;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant