无法在DataTables的drawCallback()中以编程方式选择行

时间:2015-10-10 08:05:00

标签: javascript jquery datatable

我正在使用带有select扩展名的最新数据表。我试图在表格渲染后以编程方式选择多行。我试图在drawCallback()中实现这一点,如下所示:

ScriptManagerProxy

但是,我收到var table = $('#example').DataTable({ "select": { "style": 'multi' }, "columns": [ { "data": "name" }, { "data": "position" }, { "data": "office" }, { "data": "age" }, { "data": "start_date" }, { "data": "salary" } ], "rowId": "name", "drawCallback": function( settings ) { var api = new $.fn.dataTable.Api( settings ); api.rows(["[id='Bradley Greer']", "[id='Ashton Cox']"]).select(); } }); 错误。

以下是实时版本的链接 - http://splitscreenapp.com/

P.S:我使用Uncaught TypeError: Cannot read property 'style' of undefined作为选择器,因为ID中有空格。我必须为现场演示执行此操作,这不是引发错误的原因。

1 个答案:

答案 0 :(得分:1)

  

<强>解

选项drawCallback不是执行行选择的正确位置。

理想情况下,您应该使用initComplete选项,但有一个issue的Select扩展名为fixed 10/7/15,这会阻止Select在import java.util.*; import java.io.*; import java.nio.*; import java.net.*; //... setup code ... Datagram connection = null; try { address = new InetSocketAddress(hostName, portNum); //Assume the hostName and portNum are valid (i.e. localhost, port 8250) connection = new DatagramSocket(address); connection.setSoTimeout(100); //This doesn't seem to work, even if I set this to 1000000 } catch (IOException e) { //Quit System.out.println(ERROR_UNABLE_TO_CONNECT); return; } //... read contents from sourceFile and create a DatagramPacket for sending first few bytes ... boolean received = false; byte[] ackPacketBuffer = new byte[1000]; DatagramPacket ackPacket = new DatagramPacket(ackPacketBuffer, ackPacketBuffer.length); while(!received) { try { connection.send(fileNamePacket); //fileNamePacket can be treated as the packet to be sent connection.receive(ackPacket); //From my understanding, this should block at least for the set time, before throwing SocketTimeoutException //... do some checks on the ackPacket, set received flag to be true if successful so that loop is broken... } catch (SocketTimeoutException e) { //Packet potentially lost, resend System.out.println(ERROR_TIMEOUT); continue; } catch (IOException e) { System.out.println(ERROR_SOCKET_WRITE); continue; } } 中工作。在此之前,您可以使用下面的解决方法获取HTML源数据,或使用nightly build DataTables和Select扩展。

对于包含HTML源数据的表,您可以在DataTables初始化后选择行。

initComplete
  

<强>样本

请参阅this example以获取包含HTML源数据的表的变通方法的代码和演示。

有关使用Ajax源数据的表使用夜间JS / CSS构建的代码和演示,请参阅this example。此示例也可用于HTML源数据。