jQuery UI Widgets Forums DataTable on('rowClick'): why is args.index == -1

This topic contains 2 replies, has 2 voices, and was last updated by  Tony Soprano 8 years, 7 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • Tony Soprano
    Participant

    Hello jqWidgets community
    I have a datatable with a ‘delete’ link.
    The delete of the row works in some cases, but in some cases args.index is -1,
    I cannot figure out what the problem is.

    Does anybody have an idea what I’m doing wrong?
    Any help is appreciated.
    Thanks a lot!
    Tony

    Here’s my source:

    $( “#AddPriceButton” ).click(function() {

    var row = {};

    row[“price”] = $(“#Price”).val() + ” USD”;

    $(“#PriceTable”).jqxDataTable(‘addRow’, null, row, ‘first’);

    $(“#PriceTable”).show();

    $(“#PriceTable”).jqxDataTable(‘refresh’);

    });

    var priceTableSource =
    {
    datatype: “array”,
    datafields:
    [
    { name: ‘price’, type: ‘string’ }
    ]
    };

    var priceDataAdapter = new $.jqx.dataAdapter(priceTableSource);

    $(“#PriceTable”).jqxDataTable({
    width:”100%”,
    source: priceDataAdapter,
    altRows: false,
    pageable: false,
    pagerButtonsCount: 3,
    pageSize: 3,
    columnsResize: true,
    sortable: false,
    theme: “mik-custom”,
    pagerHeight: 55,
    filterable: false,
    filterMode: ‘simple’,
    filterHeight: 50,
    columns: [
    { text: ‘Price’, dataField: ‘price’, width: “30%” },
    { text: ”, width: “20%”,
    cellsRenderer: function (row, column, value, rowData) {

    var html = “<div align=’center’>Delete</div>”;
    return html;
    }
    },
    ]
    });

    $(“#PriceTable”).on(‘rowClick’, function (event) {
    // event args.
    var args = event.args;
    // row data.
    var row = args.row;
    // row index.
    var index = args.index;
    // row’s data bound index.
    var boundIndex = args.boundIndex;
    // row key.
    var key = args.key;
    // data field
    var dataField = args.dataField;
    // original click event.
    var clickEvent = args.originalEvent;

    switch(clickEvent.target.id){

    case “DeletePriceButton”:

    $(“#PriceTable”).jqxDataTable(‘deleteRow’, index);

    var rows = $(“#PriceTable”).jqxDataTable(‘getRows’);
    if( rows.length == 0) {
    $(“#PriceTable”).jqxDataTable(‘refresh’);
    $(“#PriceTable”).hide();
    }

    break;

    }

    });


    ivailo
    Participant

    Hi Tony,

    You don’t have set DeletePriceButton as id and your case block will never be executed.
    If we remove the check about target.id everything looks to work normal.

    Here is an example javascript code.

    Best Regards,
    Ivailo Ivanov

    jQWidgets Team
    http://www.jqwidgets.com


    Tony Soprano
    Participant

    Hello Ivailo
    Thanks so much for helping me, you led me to a solution.
    It’s true the block would never been executed that way,
    however after trying your solution which actually works perfectly,
    but did not work on in my project, I downloaded the new jqwidgets version,
    which corrected this bug (my version is about 3 months old)
    In the future I will first download a new version before posting here.
    have a great weekend
    tony

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.