Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在列排序后从jquery dataTable中获取正确的行数据?_Javascript_Html_Jquery Ui_Datatables - Fatal编程技术网

Javascript 如何在列排序后从jquery dataTable中获取正确的行数据?

Javascript 如何在列排序后从jquery dataTable中获取正确的行数据?,javascript,html,jquery-ui,datatables,Javascript,Html,Jquery Ui,Datatables,我使用jquerydatatable显示客户记录。第一次进入客户页面时,我在dataTable中有20条客户记录,按 描述中的customerId列(因此从20到1显示,其中20是第20个客户的id,1是第一个客户的id) 秩序。第20个客户显示在数据表的顶部 现在,如果在我的javascript代码中执行以下操作 var customerTable=$('#customer').dataTable();// where customer is the html div associated

我使用jquerydatatable显示客户记录。第一次进入客户页面时,我在dataTable中有20条客户记录,按 描述中的customerId列(因此从20到1显示,其中20是第20个客户的id,1是第一个客户的id) 秩序。第20个客户显示在数据表的顶部

现在,如果在我的javascript代码中执行以下操作

 var customerTable=$('#customer').dataTable();// where customer is the html div associated with dataTable

 var custData = customerTable.fnGetData(18)// it gives me data of 19 row in dataTable( as dataTable index starts from 0)
 // so i get the data of customer having customer id=19
到这里都很好。

现在我单击customerId列上的排序图标。因此,在对id为1的客户进行排序后,数据表的顶部将显示id为20的客户 将显示在底部。现在我再次执行myjavascript操作

var customerTable=$('#customer').dataTable();

 var custData = customerTable.fnGetData(18)
 // it should give me data for customer id=2 Right? but still i am getting the old data i.e customer Data having id=19.
为什么排序后我没有得到正确的数据?如何在dataTable之后获得具有行id的正确数据
排序?

我尝试了同样的方法,但变化不大

第一个创建的用于保存表的全局变量

var customerTable;
然后在onready状态下启动对象

$(document).ready(function() {
        customerTable = $('#customer').dataTable();
});
如果你现在排序并获取数据。你可能会得到你想要的

var custData = customerTable.fnGetData(18);

我知道的唯一一件事是排序后我没有启动表对象。

我已经这样做了,我已经创建了customerTable作为全局变量,但问题仍然存在。奇怪。这对我很管用。我认为您需要进行更多的调试,以了解更改发生在哪个阶段-