iSortCol_(int) and sSortDir_(int)

iSortCol_(int) and sSortDir_(int)

vinck88vinck88 Posts: 2Questions: 0Answers: 0
edited March 2013 in DataTables 1.9
Hello,

I am doing server-side processing with an ASP.NET 2.0 webservice (*.asmx).

A method needs to have a fixed number of parameters and the problem is that aoData contains iSortCol_(int) and sSortDir_(int) only if the column is sorted.

For example if column 2 is not sorted I'd like to have iSortCol_2 = null and sSortDir_2 = null in aoData so that I can use nullable parameters in webservice method.

Is there a better way than doing it manually ?

Thanks.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > For example if column 2 is not sorted I'd like to have iSortCol_2 = null and sSortDir_2 = null

    That's not how the indexing works. You can have 0 or more columns sorting in DataTables, so in `iSortCol_{i}` and `sSortDir_{i}` the `{i}` refers to the sorting index (i.e the the order the sort is applied in).

    If for example you have `iSortCol_2` for column 2's sorting, how would you know if it was to be sorted before or after column 4 (if that was also being sorted at the same time).

    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you have to define them all, then the `{i}` can go up to the number of columns in the table.

    Allan
  • vinck88vinck88 Posts: 2Questions: 0Answers: 0
    Ok ... the order of the sort for multi column sorting, I forgot this one.

    So I did it manually (jaxon just makes an ajax call):
    [code]"fnServerData": function (sSource, aoData, fnCallback) {
    var data = aoDataToArray(aoData);
    data['lang'] = lang;
    jaxon({
    url: sSource,
    data: data,
    success: function (data, status, xhr) {
    fnCallback(data);
    }
    });
    }
    [/code]

    [code]
    function aoDataToArray(aoData) {
    var data = new Object();
    for (var i in aoData) {
    data[aoData[i].name] = aoData[i].value;
    }
    for (var i = 0 ; i < data['iColumns'] ; i++) {
    if (data["iSortCol_" + i] === undefined) {
    data["iSortCol_" + i] = null;
    data["sSortDir_" + i] = null;
    }
    }
    return data;
    }
    [/code]

    Now I have a constant number of parameters and I can call my WS. Of course the multi column sorting is not working anymore but I don't need it.

    Thanks Allan.
This discussion has been closed.