order.dt fired after ajax call

order.dt fired after ajax call

n2losen2lose Posts: 12Questions: 3Answers: 0

Hi @colin ,

I am using server side settings to init DataTable and I got an issue about order.dt event fire after ajax request.

I would like to custom orderField and orderType and they can be change, update dynamic from query url, last state, sorting by click on the icon up, down in table header,.....So that, I create in input hidden field to keep it, all changes need to be update it into input hidden field, and when Data Table init, It will take this options from input hidden field.
Example here: http://live.datatables.net/tefavivi/1/edit
As you can see, the order.dt event just fired once table draw, the order.dt info was log after ajax request done\

Do you know if we have an event to update the ajax.data (for orderField, orderType) when its updated before ajax called?

Replies

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @n2lose ,

    I don't quite follow what you're asking for - but you can change or add to the data being send by Ajax with ajax.data, there's a few examples on that page.

    Hope that does the trick,

    Cheers,

    Colin

  • n2losen2lose Posts: 12Questions: 3Answers: 0

    Hi @colin ,

    Thank you for helping me.
    As you can see log in my example, the ajax.data option run before order.dt even.
    Please see the code in the comment:

        //                 if (data.order.length > 0) {
        //                    var orderFieldName = data.columns[data.order[0].column].data;
        //                    var orderFieldType = data.order[0].dir;
        //                    var requestOrder = {"orderField": orderFieldName, "orderType": orderFieldType};
        //                 }
    

    It works fine but that mean I can not change order settings by the way:

        var strSortingOrder = $("#sorting-order").val();
                        var arrSortingOrder = strSortingOrder.split(",");
                        var requestOrder = {"orderField": arrSortingOrder[0], "orderType": arrSortingOrder[1]};
    

    So, I just want to know if there is any other ways to update?

    Thanks,
    Lam

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @n2lose ,

    I'm really sorry, but I'm not following - maybe the coffee just hasn't kicked in yet. With that example you sent, could you say exactly what you want, with steps to reproduce.

    Cheers,

    Colin

  • n2losen2lose Posts: 12Questions: 3Answers: 0

    Hi @colin ,

    Actually, I just want to know if we have an order event that fired before ajax request?

    In my example, when we click on the table header to reorder data, I am using the event order.dt, but it fired after ajax request to draw table.

  • kthorngrenkthorngren Posts: 20,315Questions: 26Answers: 4,771

    I'm not sure I follow what you are wanting to do but you might be able to use the preXhr event to process the server side request before its sent to the server.

    Kevin

This discussion has been closed.